Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF PropertyGrid , +
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):
[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:
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:
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 15-Oct-12 8:43am
Edited 16-Oct-12 5:21am
v4

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

  Print Answers RSS
0 OriginalGriff 250
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 DamithSL 125
4 Afzaal Ahmad Zeeshan 120
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 16 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100