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 have a PropertyGrid, that used for editing multiply objects through SelectedObjects way.
How can I execute some code before property value writen to a first component and after property value writen to last component after editing?
|
|
|
A multiple selection is represented by a MultipleObjectWrapper, which implements INotifyPropertyChanging and INotifyPropertyChanged. The PropertyChanging event is raised before the value is written to the first selected object, and PropertyChanged after the value is written to the last selected object. You can get at the MultipleObjectWrapper in two ways: 1. Construct it explicitly. Instead of setting grid.SelectedObjects = ..., write the following: MultipleObjectWrapper mow = new MultipleObjectWrapper(...); 2. Retrieve it from SelectedObject after setting SelectedObjects: grid.SelectedObjects = ...; You can then attach listeners to the PropertyChanging and PropertyChanged events. |
|
|
Thanks! It works fine.
But, I need to create a TextEditor, that changing value in related objects on leaving focus or pressing the Enter key. Is it possible? All standard editors are changing properties in selected objects on every symbol typed.
|
|
|
PropertyChanging\PropertyChanged event does not raised, when I press a button on "a “multiple values” indicator". The callstack is:
--------------------------------------------------------------------
PropertyDescriptor.SetValue()
Mindscape.WpfPropertyGrid.dll!#c.#1p.Value.set(object value = null)
Mindscape.WpfPropertyGrid.dll!Mindscape.WpfPropertyGrid.Many.Value.set(string value = null)
Mindscape.WpfPropertyGrid.dll!Mindscape.WpfPropertyGrid.Many.Reset()
Mindscape.WpfPropertyGrid.dll!Mindscape.WpfPropertyGrid.ManyEditor.#Ur(object sender = {Mindscape.WpfPropertyGrid.ManyEditor}, System.Windows.Input.ExecutedRoutedEventArgs e = {System.Windows.Input.ExecutedRoutedEventArgs})
PresentationCore.dll!System.Windows.Input.CommandBinding.OnExecuted(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
--------------------------------------------------------------------
This is by design? How can I handle reset value?
|
|
|
Create a custom editor consisting of a TextBox, and give the binding an UpdateSourceTrigger of LostFocus instead of PropertyChanged (which is what the standard editor's binding uses). (You will probably also need to handle keyboard events in order to handle the Enter key.) |
|
|
This is a bug, which is related to the fact that the new value is the same as the placeholder value returned if you query the "value" of an inconsistent property. It will be fixed in nightly builds dated 3 June 2009 and above, available after about 1430 GMT. Please let us know if you still run into problems. |
|
|
[quote user="ivan"] Create a custom editor consisting of a TextBox, and give the binding an UpdateSourceTrigger of LostFocus instead of PropertyChanged (which is what the standard editor's binding uses). (You will probably also need to handle keyboard events in order to handle the Enter key.) [/quote] Is there a way to tell to PropertyGrid to always use our TextBox instead default or it has to be defined for every data type that TextBox is used for? |
|
|
I think you can do this by hijacking the SimpleTextEditorKey data template resource. For an example of how to do this, look at how Alloy.xaml (in the Source / Styles directory) hijacks the ReadOnlyDisplayKey to customise the appearance of read-only text blocks. Replacing the entire data template in this way allows you to define your own text box binding (with your own UpdateSourceTrigger). Let me know if you need further info about how to apply this to your text box scenario. |
|