This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I need to be able to dynamically enable/disable editing of a property based on the value of another property. For example, if string property X is non-empty then string property Y editor is disabled, else it is enabled. Are there events that can be hooked to do this programmatically or would you need to set up some special treatment of properties by name in the xaml? Any examples would be much appreciated.
|
|
|
There are no special events for this -- you could hook INotifyPropertyChanged on your business object but by the time X changes, the editor template for Y has already been instantiated, so I don't think you'd be able to do anything particularly useful. So you would need to create a custom editor for Y which is aware of X and contains appropriate triggers or bindings. The trick to this is that a PropertyEditor DataTemplate gets bound to an ObjectWrapper, which is where the mysterious "Value" property comes from. Normally Value is all you need or want in an editor template. But ObjectWrapper also allows you to get at some additional contextual information, such as the Node being edited (from which you can get hold of property metadata) and the UnderlyingObject (from which you can get at other property values). So in your example you can create a property editor template something like: <DataTemplate x:Key="YEditor"> (Forgive any syntax errors, I'm typing this directly into the forums.) For more complex UI changes you could also use a DataTrigger. Note that, as usual for WPF data binding, your object will need to raise PropertyChanged events for X in order for WPF to be able to respond and enable/disable appropriately. |
|