Here is an example that fully reproduces your problem:
<StackPanel> <StackPanel.Resources> <l:MyBool x:Key="MyBool" IsTrue="False" /> </StackPanel.Resources> <CheckBox x:Name="myCheckBox" Content="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsChecked}" IsChecked="{Binding Source={StaticResource MyBool}, Path=IsTrue, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Top"> <CheckBox.Triggers> <EventTrigger RoutedEvent="UIElement.MouseEnter"> <BeginStoryboard x:Name="isCheckedBeginStoryboard"> <Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsChecked"> <DiscreteObjectKeyFrame KeyTime="0"> <DiscreteObjectKeyFrame.Value> <System:Boolean>True</System:Boolean> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="UIElement.MouseLeave"> <StopStoryboard BeginStoryboardName="isCheckedBeginStoryboard" /> </EventTrigger> </CheckBox.Triggers> </CheckBox> <CheckBox Content="Also two way binding to MyBool.IsTrue no animation" IsChecked="{Binding Source={StaticResource MyBool}, Path=IsTrue}" /> <TextBlock Text="{Binding Source={StaticResource MyBool}, Path=IsTrue, StringFormat={}MyBool.IsTrue: {0}}" /> <TextBlock Text="{Binding ElementName=myCheckBox, Path=IsChecked, StringFormat={}myCheckBox.IsChecked: {0}}" /> </StackPanel>
Where MyBool is a simple class that also implements INotifyPropertyChanged :
public class MyBool : INotifyPropertyChanged { private bool _isTrue; public bool IsTrue { get { return _isTrue; } set { if (_isTrue != value) { _isTrue = value; NotifyPropertyChanged("IsTrue"); } } } public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string propertyName) { if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)); } }
As you can see from this run, when the animation is active, your StaticResource not updated when the animation is NOT active. This happens when the animation starts WPF, gives a new value for the IsChecked property (as defined by your Storyboard ). This effectively overrides the old value - two-way Binding to StaticResource . Once the animation has finished and stopped, WPF will return the old IsChecked value back to the original binding expression, so your MyBool resource will continue to receive updates.
An excellent article on prioritizing DependencyProperty values ββcan be found here:
http://msdn.microsoft.com/en-us/library/ms743230.aspx
Hope this helps!
source share