I have a XamComboEditor that is bound to a Class. When the user selects an item from the dropdown, the PropertyChanged event for the bound property is fired twice!
<igEditors:XamComboEditor Grid.Row="0" Grid.Column="1" x:Name="cbxInputName" IsEditable="True" DisplayMemberPath="FieldName" ValuePath="FieldName" Value="{Binding Path=InputName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True}" />
I bind the Itemsource as Follows this.cbxInputName.ItemsSource = Wrap.Fields;
Where Fields has a string property "FieldName" that I want to be both the Value and the Display
If I simply remove the IsEditable value - then the propertyChanged event only fires once. Any Suggestions.
Rod
When you have a binding on a property, the binding's source will be updated any time the bound property is set even if the value has not changed. So for example if you were to bind a TextBox's Text property to the underlying object and set the Text property of the textbox twice to the same string value (even if its the same string reference), the underlying binding will set the value on the source for each call to SetValue. The normal implementation for a setter of an object that implements INotifyPropertyChanged is to compare the value being handed in against the current member variable and only raise the event if they differ. e.g.
I am not programmatically setting the value on my control. I don’t think you fully understand the problem I am describing (or I am completely missing the boat somewhere).
To Simplify: in my XamComboEditor – I can change the event behavior by changing the value of IsEditable and nothing more.
IF isEditable=”false” everything works properly and life is good. The PropertyChanged Event only fires ONCE when a NEW VALUE is selected from the combodropdown.
IF isEditable=”true” the propertyChanged event fires TWICE when a NEW VALUE is selected from the combodropdown.
In both scenarios, if the current value is selected, then the property changed event does not fire.
Now, to go a bit more complex… If I were to type in the Editable XamComboEditor, the PropertyChanged Event is fired ONCE for each Keystroke that is pressed within the XamComboEditor. (this is a good thing)
So my fundamental question is, WHY is the property Changed event fired TWICE ONLY when the IsEditable value = true? In every other situation the behavior is as expected.
My guess is that in the internal implementation of the XamComboEditor, when you overlay the ComboBox with the text box (to allow editing) you are binding directly back to the bound object, instead of back to the property within the combo editor – this is forcing the property on our bound object to be set ‘twice’ (originating from within infragistics library) and not my source code.
I am unable to change the implementation of the Property setter as the classes are generated through the Visual Studio XSD.Exe tool.
RodBillett said: I am not programmatically setting the value on my control. I don’t think you fully understand the problem I am describing (or I am completely missing the boat somewhere).
RodBillett said: So my fundamental question is, WHY is the property Changed event fired TWICE ONLY when the IsEditable value = true? In every other situation the behavior is as expected.
RodBillett said: I am unable to change the implementation of the Property setter as the classes are generated through the Visual Studio XSD.Exe tool.
I believe that the WPF DependencyObject binding doesn't call the property setter when focusing the control, it only calls the setter after typing.Take a simple WPF TextBox and set UpdateSourceTrigger=PropertyChanged, it won't call the property setter, infragistics sadly does and evaluating the value in the setter isn't really an option.
It's true that they don't set the TextBox doesn't set its Text property when getting/losing focus but our control offers more functionality and one of the things it does as part of its behavior is to re-evaluate the Text representation of the Value when entering/exiting edit mode. One reason is that the ValueToTextConverter could be basing the result on the edit mode state - e.g. to apply or not apply formatting. Also, this is only happening with the Text property in the case of the xamTextEditor and entering/exiting edit mode. You could just bind to the Value property instead.
With regards to checking the value in the setter, I believe this is the common practice. Even the example snippet in Microsoft's documentation for the INotifyPropertyChanged interface does this.
Wanted to update everyone on this bug. It has been fixed in the current service release 11.2.20112.2046