title: Binding a Storyboard property relative to the target of the storyboard
body: <p>I have a storyboard which targets an element, and binds one of its own properties to a property on another element:</p>
  
  <pre><code>&lt;Storyboard&gt;
    &lt;DoubleAnimation 
              Storyboard.TargetProperty="RenderTransform.X" 
              From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualWidth}" 
              To="0" 
              Duration="0:0:5"/&gt;
   &lt;/Storyboard&gt;
  </code></pre>
  
  <p>This storyboard works when the storyboard is stored in the resources of the window which holds the storyboard target.  The 'From' value is correctly bound to the ActualWidth of the host Window instance.<br/><br/>
  However, I need to store the storyboard in my application level resources. From here, the storyboard does not seem to be able to target the window to determine the 'From' property.  This is understandable as from inside <code>&lt;Application.Resources&gt;</code>, the binding won't be able to find an 'ancestor' of type Window. <br/><br/>
  I guess I need to be able to bind the 'From' value, relative to the target of the animation, rather than relative to the storyboard's <code>DoubleAnimation</code>.<br/><br/></p>
  
  <p>Is this possible, and if so, how?
  <br/> <br/>
  Here is the sample MainWindow.xaml:</p>
  
  <p></p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;!--This works : Storyboard correctly sets 'From' property to 'ActualWidth' of window--&gt;
      &lt;Storyboard x:Key="localStoryBoard"&gt;
          &lt;DoubleAnimation 
              Storyboard.TargetProperty="RenderTransform.X" 
              From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualWidth}" 
              To="0" 
              Duration="0:0:5"/&gt;
      &lt;/Storyboard&gt;
  &lt;/Window.Resources&gt;
  &lt;StackPanel&gt;
  
      &lt;Button
          RenderTransformOrigin="0,1"
          HorizontalAlignment="Left"
          Content="Click me"&gt;
  
          &lt;Button.RenderTransform&gt;
              &lt;TranslateTransform/&gt;
          &lt;/Button.RenderTransform&gt;
          &lt;Button.Triggers&gt;
              &lt;EventTrigger RoutedEvent="Button.Click"&gt;
                  &lt;EventTrigger.Actions&gt;
                      &lt;BeginStoryboard Storyboard="{StaticResource centralStoryBoard}"/&gt;
                  &lt;/EventTrigger.Actions&gt;
              &lt;/EventTrigger&gt; 
          &lt;/Button.Triggers&gt;
      &lt;/Button&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p></p>
  
  <p>And here is an example app.xaml:</p>
  
  <pre><code>&lt;Application x:Class="WpfApplication3.App"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               StartupUri="MainWindow.xaml"&gt;
      &lt;Application.Resources&gt;
          &lt;!--Storyboard doesn't work at all--&gt;
          &lt;Storyboard x:Key="centralStoryBoard"&gt;
              &lt;DoubleAnimation 
                  Storyboard.TargetProperty="RenderTransform.X" 
                  From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualWidth}" 
                  To="0" 
                  Duration="0:0:5"/&gt;
          &lt;/Storyboard&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>This won't work, as the eventtrigger refers to the app.xaml version.  If you change it to the local resource version, you can see it works.</p>