Property Level Definitions

Editors for WPF Forum

Posted 10 years ago by Jerry Pile
Version: 13.2.0592
Avatar

Hi,

I am trying to implement a BrushPropertyEditor at the property level,  I would like to dynamically add object properties at runtime. I seem to be missing something. Here is a code snippet:

public partial class MainWindow : Window        
    {
        myObject obj = new myObject { MyBrush = Brushes.Silver };
       
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {           
            propertyGrid1.SelectedObject = obj;
        }
        
    }


    public class myObject
    {
        [Category("Colors")]
        [DisplayName("SomeColor")]
        [Editor (typeof(BrushPropertyEditor), typeof(PropertyEditor))]
        public Brush MyBrush { get; set; }
        
    }

 What am I missing? I have also tried to add the BrushPropertyEditor to the PropertyGrid PropertyEditors:

 <propgrid:PropertyGrid Height="272" HorizontalAlignment="Left" Margin="116,103,0,0"  Name="propertyGrid1" VerticalAlignment="Top" Width="211">
            <propgrid:PropertyGrid.PropertyEditors>
                <propgrid:BrushPropertyEditor PropertyName="MyBrush"/>
            </propgrid:PropertyGrid.PropertyEditors>
        </propgrid:PropertyGrid>

 All I really want to do is use a ColorEditor in the PropertyGrid for all the Brush color properties that the object may have. The PropertyGrid does not get populated until the user selects the object at runtime, so everything needs to be done in the code behind. I know that there are several other ways to do this, but the property level definition seemed like the easiest.

Thanks,

Jerry

Comments (2)

Answer - Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Jerry,

When I add your code, I do see the basic BrushPropertyEditor that shows a swatch and allows for typing of the brush color.

If you mean that you see that but want it to use the nicer brush editor that is part of Editors, you need to reference the "ActiproSoftware.Editors.Interop.PropertyGrid.Wpf.dll" assembly.  You can comment out the PropertyGrid.PropertyEditors section in your XAML and then update your editor attribute in the object to be:

[Editor(typeof(ActiproSoftware.Windows.Controls.Editors.Interop.PropertyGrid.PropertyEditors.BrushPropertyEditor), typeof(PropertyEditor))]
public Brush MyBrush { get; set; }

If I do those things then I have the nice drop-down that is part of the Editors' brush editor.


Actipro Software Support

Posted 10 years ago by Jerry Pile
Avatar

Thank you!

I was referencing the ActiproSoftware.Windows.Controls.PropertyGrid.Editors.BrushPropertyEditor (which does not appear to do anything), instead of the ActiproSoftware.Windows.Controls.Editors.Interop.PropertyGrid.PropertyEditors.BrushPropertyEditor.

Jerry

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.