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
670
XamComboEditor and OneWay binding
posted

Hello,

I have a problem with the OneWay BindingMode using a XamComboEditor : the selected item is updated only the first time I change the source.

If I use the TwoWay mode it's working perfectly (but the source is updated if I change the selected item and that's not what I want).

Here's my code :

<igEditors:XamComboEditor ValuePath="ColonneName" DisplayMemberPath="LibelleSource" ItemsSource="{Binding ColGroupes}" Value="{Binding ParametresEtat/fldString1, Mode=OneWay}" HorizontalAlignment="Left" Margin="12,48,0,0" Width="155" Height="19.555" VerticalAlignment="Top" Name="cbGroupe">
  <igEditors:XamComboEditor.ComboBoxStyle>
    <Style TargetType="{x:Type ComboBox}">
      <Setter Property="IsSynchronizedWithCurrentItem" Value="true"/>
    </Style>
  </igEditors:XamComboEditor.ComboBoxStyle>
</igEditors:XamComboEditor>

Please do you have any suggestion ?

Thanks

  • 54937
    Verified Answer
    Offline posted

    When you set a Binding for a property value as you have, WPF stores that as the local value. When something changes the value of that property (e.g. control needs to set it when you select an item, type into the edit, etc.) then WPF will use that as the new local value replacing the binding that you have set. WPF treats a two way binding specially and maintains the binding and pushes the value back into the source object. This would happen for any wpf property where the object needs to set the value of its property - e.g. the Text property of a TextBox.

    Just so I understand what you are trying to accomplish, you want to have the initial value come from your source, you never want changes in the control to be pushed back into your source object but the control is modifiable by the end user, and you want the Value of the control to update if the source property value changes later? So you will either need to use a two way binding, hook the ValueChanged and programatically push the value back into the source, or perhaps write your own attached property and have that programatically push changes into the Value property.