I have a ToggleButton
with its IsChecked
property bound to a property using a OneWay binding.
<ToggleButton
Command="{Binding Path=SomeCommand}"
IsChecked="{Binding Path=SomeProperty, Mode=OneWay}" />
The SomeCommand
toggles the boolean SomeProperty
value, and a PropertyChanged
event is raised for SomeProperty
.
If I change SomeProperty
in my viewmodel the ToggleButton
depresses correctly. However if I click the ToggleButton
the binding seems to get lost and the button no longer gets checked according to the value of SomeProperty
. Any ideas on how to fix this problem?
To my knowledge Sinatr is correct regarding the 'desync' that occurs, at least in newer frameworks.
Another simple way around the issue is to remove the mode=oneway and implement an empty setter. Ex:
bool _MyIsEnabled;
public bool MyIsEnabled
{
get { return _MyIsEnabled; }
set { }
}
With this binding setup you can you change the value of the backing variable from your command binding function, or from whether you need to. Just remember to call RaisePropertyChanged.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With