Why am I getting inconsistent binding results

I have a control template with a toggle button. This ToggleButton has an IsChecked property associated with a dependency property. If I set the dependency property explicitly it works.

The problem is that after I interact with the toggle button in the UI, the bindings don't update the IsChecked property if I set the dependency property explicitly.

I've got it working arround using a TwoWay binding that works great. My question is, why does it behave like this? Am I missing something? Is there a bug in the Silverlight binding mechanism?

EDIT INCLUDING SNiPPP:

The binding in the ControlTemplate looks something like this (can be replaced with TemplateBinding)

<ToggleButton x:Name="PlayPause" Grid.Column="0" 
              IsChecked="{Binding Paused, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
              HorizontalAlignment="Center"
              Width="50" Height="50"/>

      

An explicit parameter for the dependency property is the standard swamp standard:

myComponent.Paused = true;

      

+2


source to share


2 answers


WPF removes one-way bindings when the target property changes (IsChecked in this case). Silverlight was used to preserve the binding across IsChecked changes. If Paused was set later, this value will also overwrite IsChecked.



In your opinion Silverlight has reverted back to WPF behavior. Well. Personally, I think changing the bound property is a bug. If the properties aren't meant to be in sync, the command might be the best solution.

+2


source


  • You must use TwoWay binding
  • Make sure the object containing your Paused property supports INotifyPropertyChanged.
  • Make sure the setter for Paused fires the PropertyChanged event


+1


source







All Articles