Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1886
XamComboEditor Iseditable=True and Binding (Property is 'set' twice)
posted

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

  • 54937
    Offline posted

    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.

    public string FieldName
    {
    get { return _fieldName; }
     
    set
    {
    if (value != _fieldName)
    {
    _fieldName = value;
    this.RaisePropertyChangedEvent("FieldName");
    }
    }
    }