title: Dependency Property Value Precedence and animations
body: <p>I am animating some property using <code>DoubleAnimation</code>. Before animation is triggered any local or <code>Setter</code> changes are properly reflected in the property. After animation completes nothing seems to be able to change the value of the property. I have even tried <code>ClearValue</code> and <code>InvalidateProperty</code> as well set calling <code>SetValue</code> but the value leftover from animation persists. If animation is repeated, the property continues to be animated as expected so it only appears to be locked for non-animation changes.</p>
  
  <p>Is there a way to rectify this behavior? I want to use the animation to change the property value but still be able to change it manually or via a <code>Setter</code> to anything else. I know a thing or two about <a href="http://msdn.microsoft.com/en-us/library/ms743230.aspx" rel="nofollow">Dependency Property Value Precedence</a> but the behavior I am currently experiencing is a bit strange. I'd hate to have to use "manual animations".</p>
  
  <p>EDIT: Added sample XAML + code.</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication7.Window1"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          Title="Window1" Height="300" Width="300"
          x:Name="_this"
          Background="Red"&gt;
      &lt;DockPanel&gt;
          &lt;StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center" &gt;
              &lt;Button Click="ToggleOnClick"&gt;Toggle!&lt;/Button&gt;
              &lt;Button Click="SetHalfOnClick"&gt;Set to 0.5!&lt;/Button&gt;
          &lt;/StackPanel&gt;
          &lt;TextBox DockPanel.Dock="Bottom" IsReadOnly="True" Text="{Binding ElementName=_viewbox,Path=Opacity}" /&gt;
          &lt;Viewbox x:Name="_viewbox"&gt;
              &lt;Viewbox.Style&gt;
                  &lt;Style TargetType="{x:Type FrameworkElement}"&gt;
                      &lt;Style.Triggers&gt;
                          &lt;DataTrigger Binding="{Binding Path=IsToggled,ElementName=_this,Mode=OneWay}" Value="True"&gt;
                              &lt;DataTrigger.EnterActions&gt;
                                  &lt;BeginStoryboard&gt;
                                      &lt;Storyboard&gt;
                                          &lt;DoubleAnimation To="0.2"
                                                   Duration="0:0:0.5"
                                                   Storyboard.TargetProperty="(UIElement.Opacity)" /&gt;
                                      &lt;/Storyboard&gt;
                                  &lt;/BeginStoryboard&gt;
                              &lt;/DataTrigger.EnterActions&gt;
                              &lt;DataTrigger.ExitActions&gt;
                                  &lt;BeginStoryboard&gt;
                                      &lt;Storyboard&gt;
                                          &lt;DoubleAnimation To="1"
                                                   Duration="0:0:0.5"
                                                   Storyboard.TargetProperty="(UIElement.Opacity)" /&gt;
                                      &lt;/Storyboard&gt;
                                  &lt;/BeginStoryboard&gt;
                              &lt;/DataTrigger.ExitActions&gt;
                          &lt;/DataTrigger&gt;
                      &lt;/Style.Triggers&gt;
                  &lt;/Style&gt;
              &lt;/Viewbox.Style&gt;
  
              &lt;TextBlock Text="Sample!" /&gt;
          &lt;/Viewbox&gt;
      &lt;/DockPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>using System.Windows;
  
  namespace WpfApplication7
  {
      /// &lt;summary&gt;
      /// Interaction logic for Window1.xaml
      /// &lt;/summary&gt;
      public partial class Window1
      {
          public bool IsToggled
          {
              get { return (bool)GetValue(IsToggledProperty); }
              set { SetValue(IsToggledProperty, value); }
          }
  
          public static readonly DependencyProperty IsToggledProperty = DependencyProperty.Register("IsToggled", typeof(bool), typeof(Window1), new UIPropertyMetadata(false));
  
          public Window1()
          {
              InitializeComponent();
          }
  
          private void ToggleOnClick(object sender, RoutedEventArgs e)
          {
              IsToggled = !IsToggled;
          }
  
          private void SetHalfOnClick(object sender, RoutedEventArgs e)
          {
              _viewbox.Opacity = 0.5;
          }
      }
  }
  </code></pre>