Today I update a Windows Store app according to UI design change. One of the changes is replacing a CheckBox
with a ToggleSwitch
.
So the code is updated from
<CheckBox IsChecked="{Binding BooleanProperty}" ...
to
<ToggleSwitch IsOn="{Binding BooleanProperty"} ... //does not update data source
Then I notice that toggling ToggleSwitch
does not update the underlying BooleanProperty
, I have to add Mode=TwoWay
to make it work.
<Toggleswitch IsOn="{Binding BooleanProperty, Mode=TwoWay"} ... //update data source
From what I learnt in WPF, I don't have to set Mode=TwoWay
explicitly on CheckBox's IsChecked property, because it is TwoWay
by default.
In general, user-editable control properties, such as those of text boxes and check boxes, default to two-way bindings, whereas most other properties default to one-way bindings.
And I have been thinking ToggleSwitch
is just another CheckBox with better touch support, and it is only available on Windows Store and Windows Phone apps.
Why ToggleSwitch.IsOn
is not default to TwoWay binding? Are there other differences between a CheckBox and a ToggleSwitch?