views:

75

answers:

2

I have a control template with a toggle button. This ToggleButton has it's IsChecked property one way bound to a dependancy property. If i set the dependancy property explicitly the binding 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 do have a work arround using TwoWay binding which works fine. My question is, why does it behave this way? Am I missing something? Is there a bug in the binding mechanism of Silverlight?

EDIT TO INCLUDE SNIPPET:

The binding in the ControlTemplate looks something like (could 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"/>

The explicit setting of the dependency property is the fairly bog standard:

myComponent.Paused = true;
+1  A: 
  1. You should use TwoWay binding
  2. Make sure that the object that contains your Paused property supports INotifyPropertyChanged.
  3. Make sure that the setter for Paused triggers the PropertyChanged event
Michael S. Scherotter
+2  A: 

WPF deletes one way bindings when the target property (IsChecked in this case) is modified. Silverlight used to keep the binding when IsChecked was modified. If Paused was later set, this value would overwrite IsChecked as well.

According to you, it seems Silverlight reverted to WPF behavior. Oh well. Personally, I consider modifying a binded property a bug. If the properties are not meant to be in sync commanding may be a better solution.

Bruno Martinez