Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I'm using the WPF Extended Toolkit PropertyGrid (v1.7), and I'm trying to setup a custom editor to display a dialog box when the user clicks a button. My problem is that I can't get the property grid to display the editor panel at all.

The property in question is properly adorned with the following attributes (and the property itself does show up in the propertygrid):
C#
[Editor(typeof(CDSceneSelectorEditor), typeof(DialogPropertyValueEditor))]
[Category("General")]
[DisplayName("Base Scene")]
[Browsable(true)]
public Image BaseSceneImage { get; set; }

I tried doing it as follows, but it wouldn't display the editor panel, and after some investigation in the debugger, I noticed that the template's VisualTree was null:
C#
public class CDSceneSelectorEditor : DialogPropertyValueEditor
{
    public CDSceneSelectorEditor()
    {

        string template = 
            @"<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
                            xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
//                          xmlns:pe='clr-namespace:System.Activities.Presentation.PropertyEditing;assembly=System.Activities.Presentation'>
                <DockPanel LastChildFill='True'>
                <pe:EditModeSwitchButton TargetEditMode='Dialog' Name='EditButton' 
                                         DockPanel.Dock='Right' Content='...' />
                <TextBlock Text='Picture' Margin='2,0,0,0' 
                           VerticalAlignment='Center'/>
            </DockPanel>
        </DataTemplate>";

        try
        {
            using (var sr = new MemoryStream(Encoding.UTF8.GetBytes(template)))
            {
                this.InlineEditorTemplate = (DataTemplate)(XamlReader.Load(sr));
            }
        }
        catch (Exception ex)
        {
            if (ex != null) {}
        }
    }
}

So, I figured that the visual tree must be the issue, so I tried it this way, which gave me a VistalTree, but didn't change the result:
C#
public class CDSceneSelectorEditor : DialogPropertyValueEditor
{
    public CDSceneSelectorEditor()
    {
        var button = new FrameworkElementFactory(typeof(EditModeSwitchButton))
                         { Name = "EditButton"     };
        button.SetValue(DockPanel.DockProperty, Dock.Right);
        button.SetValue(EditModeSwitchButton.TargetEditModeProperty, 
                        PropertyContainerEditMode.Dialog);
        button.SetValue(EditModeSwitchButton.ContentProperty, " ... ");
        button.SetValue(TextBlock.MarginProperty, new Thickness(0,0,3,0));

        var image  = new FrameworkElementFactory(typeof(Image))
                         { Name = "ThumbnailImage" };
        image.SetValue(Image.StretchProperty, 
                       System.Windows.Media.Stretch.Uniform);

        var panel  = new FrameworkElementFactory(typeof(DockPanel));
        panel.AppendChild(button);
        panel.AppendChild(image);

        DataTemplate template = new DataTemplate();
        template.VisualTree = panel;
        this.InlineEditorTemplate = template;
    }
}


I am out of ideas, and google has been no help at all.
Posted
Updated 16-Oct-12 4:21am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900