Single property, multiple fields

Grids for WPF Forum

Posted 14 years ago by Phillip OShea
Version: 10.2.0531
Avatar
I have a value type I want edited in the PropertyGrid, lets say, struct Point( float X, float Y, float Z ). The editable component of the entry should be 3 TextBox controls which bind to the X, Y and Z values of the property:

[ X ] [ Y ] [ Z ], not just [ X, Y, Z ]

If I setup each TextBox binding like so:
Text="{Binding Value.X, RelativeSource={RelativeSource AncestorType={x:Type Primitives:IPropertyDataAccessor}}, Mode=TwoWay}"

The initial values resolve ok, but I cannot change the value and have the actual property update.

Thoughts?

Comments (1)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Phillip,

You don't give the full definition of your struct, but Bindings don't work well with fields. They are meant to be used with properties. This article explains this better: http://stackoverflow.com/questions/842575/why-does-wpf-support-binding-to-properties-of-an-object-but-not-fields

When using PropertyGrid.SelectedObject(s), we have some special handling for structs. Specifically, when one of the "fields/properties" change we construct a new instance of the struct using the new value for the given field/property. This allows immutable structs to be presented and changed in the PropertyGrid.

You may end up having to do something similar. If you can put together a small sample project with what you have and email it to our support address, then we can take a closer look.


Actipro Software Support

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

Add Comment

Please log in to a validated account to post comments.