1

Could anyone explain me why the first binding expression is detached after I click the checkBox3 object...

<StackPanel>
    <CheckBox x:Name="chackBox1" Content="CheckBox1"
        IsChecked="{Binding ElementName=chackBox2, Path=IsChecked, Mode=OneWay}" />
    <CheckBox x:Name="chackBox2" Content="CheckBox2" IsChecked="False" />
    <CheckBox x:Name="chackBox3" Content="CheckBox3"
        IsChecked="{Binding ElementName=chackBox1, Path=IsChecked, Mode=TwoWay}" />
</StackPanel>

...and it does not happen in the following scenario...

<StackPanel>
    <CheckBox x:Name="chackBox1" Content="CheckBox1"
        IsChecked="{Binding ElementName=chackBox2, Path=IsChecked, Mode=TwoWay}" />
    <CheckBox x:Name="chackBox2" Content="CheckBox2" IsChecked="False" />
    <CheckBox x:Name="chackBox3" Content="CheckBox3"
        IsChecked="{Binding ElementName=chackBox1, Path=IsChecked, Mode=TwoWay}" />
</StackPanel>

...where the Mode is changed to TwoWay in the first binding expression?

I'm just asking for an explanation. I know how to omit that tricky situation and I know how to debug binding expressions. I found similar post here but there is no clear answer for my general problem.

Marek
  • 11
  • 3
  • `OneWay` is usually used with `TextBlock` as the Binding will work only one way and that is from Source->UIElement. – XAMlMAX May 09 '16 at 13:05

1 Answers1

0

In you first scenario, checkbox1 has a OneWay binding, so cannot accept changes to its value except via checkbox2. If checkbox3 tries to set checkbox1 then it will invalidate the binding, and set it as a raw value.

If you want checkbox3 to set checkbox1 (which updates checkbox2) then rather than a OneWay binding you need OneWayToSource

Dean Chalk
  • 20,076
  • 6
  • 59
  • 90