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.