Dynamic Properties, how to on new Editors in PropertyGrid?

Grids for WPF Forum

Posted 15 years ago by jeff jarrell
The properties that I am putting up into the property grid is a dynamic list of property objects assembled into a collection.

I am using the PropertyGrid.SelectedObject(s). I have a derived DataFactory creating instances of something that implements IPropertyDataAccessor.

I am looking at something simple like the DoubleEditBox. It's not a PropertyEditor per-se so I derive a class from PropertyEditor and override the ValueTemplate property. Here I do an Application.Current.FindResource and provide the DataTemplate. The ProperyEditor is defined in xaml and added to the BuiltInEditors.

The DataTemplate at this point includes a reference to DoubleEditBox and has bindings to the IPropertyDataAccessor.Value.
<DataTemplate x:Key="doublePropertyEditor">
                <acteditors:DoubleEditBox  Name="textBox" 
                                           Value="{Binding Value, RelativeSource={RelativeSource AncestorType={x:Type propgrid:IPropertyDataAccessor}}, Mode=TwoWay}"
1) This seems to work, but is this the proper way to create and provide a PropertyEditor in this scenario.

2) It doesn't look right as it has a border around the control in the property grid, even when the cell doesn't have focus. How do I get rid of this extra border?

3) I'd expect that I need to include a binding to the IPropertyDataAccessor.IsReadOnly, which is easy enough, but how should a change to the business object.IsEnabled bubble up. Since there is only a Getter on the IPropertyDataAccessor i need to create something like a SetEnabled() on the object that implements IPropertyDataAccessor. True?

4) Of course, if there is an example in the docs that I missed, I'd be happy for a reference.

Thanks for any help.

Comments (3)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Jeff,

The Editors is still in beta, and is going to be included as part of WPF Studio 5.0. In that we include a sample that shows how to integrate the Editors into the PropertyGrid. Additionally, we are working on an interop project that will provide default DataTemplates for you.

For your specific questions:

1. That looks like the correct way to do it. If you add an entry to the BuiltinEditors.PropertyEditors collection, then that entry will be applied globally to all instances of the PropertyGrid. If that's not what you want, then you could also add it to the PropertyGrid.PropertyEditors collection (which only affects that single instance).

2. You can set BorderThickness to 0. You may also want to adjust the Margin and/or Padding properties.

3. What you can do is bind the IPropertyDataAccessor.IsReadOnly property to the DoubleEditBox.IsEnabled property. Our shared library includes a BooleanNotConverter, which you can use in the binding to flip the boolean value.

4. There will be plenty of examples once we release WPF Studio 5.0 ;-)

Hope this helps.

Actipro Software Support

Posted 15 years ago by jeff jarrell
Great. Thanks for help and we will be looking forward to V5...

Now, I did do the binding for IsEnabled that appears to work. It gets the greyed out appearance if it is disabled and if I go to select the cell (when IsReadOnly==true) it won't take the click.

But... if i use the mouse and double click on the value (selects all text in cell), or use the mouse to select the text in the cell I can then edit it. Seems like a bug. I know it's beta but thought you'd like to know.

I confirmed that the IsReadOnly is being pushed out via a break-point on my own BooleanNotConverter.

It would be nice to look at the instance of the DoubleEditBox (defined in the DataTemplate to look at this, but how does one get to an instance of the control, given that it is defined in the data template?

If I knew the parent I suppose that DataTemplate.FindName("name",parent) would work. So I guess the question is what is the parent? The PropertyEditor is a CLR class so that isn't it.


[Modified at 05/13/2009 07:48 PM]
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Jeff,

Yup, that's a bug and thanks for letting us know about it. I've fixed this issue, so it will be correctly disabled in the RTM release.

The PropertyGrid has zero or more PropertyGridDataAccessorItem elements, which themselves can have zero or more PropertyGridDataAccessorItem elements. This is the basic tree stucture of the PropertyGrid. Inside each PropertyGridDataAccessorItem are two cells, one of the property name and one for the value. These are represented by an instance of TreeListViewCell. The DoubleEditBox would be in the value cell.

You can use the VisualTreeHelperExtended class from our Shared Library to walk up or down the visual tree from any Visual.

Actipro Software Support

The latest build of this product (v24.1.2) was released 26 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.