ToggleSwitch loses sync with bound property


I am using the Toggleswitch control to toggle an auto-refresh on off for some data retrieval on a WPF form I've developed.
The toggleswitch is bound to a property on my ViewModel that is toggled in a few places, especially in asynchronous processes via the UI dispatcher.
In some instances and quite frequently I have found that the ToggleSwitch loses sync with its bound property (normal property that raises iNotifyPropertyChanged.RaisePropertyChanged() ).
When this happens I can click on the ToggleSwitch and it stays in either the on or off state yet I see the property has been updated accordingly.
Any ideas?


Simpzon wrote Feb 8, 2013 at 9:40 AM

That's a common bug/feature of the ToggleSwitch:
Clicking the switch always toggles the IsChecked-Property.
I don't think it has anything to do with WPFSpark, it happens with normal WPF CheckBox/ToggleButton controls as well.

To workaround this, you can create a class that overrides the OnClick-Method and use it instead of the original Control:
  public class OneWayToggleSwitch : ToggleSwitch
    protected override void OnClick() {
      this.RaiseEvent(new RoutedEventArgs(ClickEvent, this));
      if (this.Command != null && this.Command.CanExecute(this.CommandParameter)) {
or alternatively you can update the binding of your toggleButton on some event:
var bnd = targetToggleButton.GetBindingExpression(ToggleButton.IsCheckedProperty);
          if (bnd != null) {

wrote Feb 14, 2013 at 7:28 PM

Arteny wrote Apr 14, 2014 at 12:50 PM

I tried to use OneWayToggleSwitch from example, but it doesn't allow to switch the control manually at all.