title: XAML: Setting the value of Storyboard animation from code behind
body: <p>I have a requirement where I need a button to move from one end of the screen to another (horizontally) in a few seconds. I tried this and works to some extent. </p>
  
  <pre><code>&lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="button"&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="0" /&gt;
              &lt;!--&lt;EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="{Binding MainPage.width}"&gt;--&gt;
                  &lt;EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="-1283.725"&gt;
                  &lt;EasingDoubleKeyFrame.EasingFunction&gt;
                      &lt;CircleEase EasingMode="EaseIn"/&gt;
                  &lt;/EasingDoubleKeyFrame.EasingFunction&gt;
              &lt;/EasingDoubleKeyFrame&gt;
          &lt;/DoubleAnimationUsingKeyFrames&gt;
          &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="button"&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/&gt;
              &lt;!--&lt;EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="{Binding Path=MainPage.height}"&gt;--&gt;
              &lt;EasingDoubleKeyFrame KeyTime="0:0:6.9" Value="-467.732"&gt;
                  &lt;EasingDoubleKeyFrame.EasingFunction&gt;
                      &lt;CircleEase EasingMode="EaseIn"/&gt;
                  &lt;/EasingDoubleKeyFrame.EasingFunction&gt;
              &lt;/EasingDoubleKeyFrame&gt;
          &lt;/DoubleAnimationUsingKeyFrames&gt;
  </code></pre>
  
  <p>But the problem is due to screen sizes &amp; screen orientation. <em>On a big screen it stops in the middle.</em> I want to set the <b>Value</b>   of <i>EasingDoubleKeyFrame</i> dynamically. Code behind or binding or any other way. </p>
  
  <p>But I don't want to write the whole storyboard in Code Behind. </p>
  
  <p>I can get the screen width &amp; height using </p>
  
  <pre><code>Rect bounds = Window.Current.Bounds;
      static double height = 0;
      static double  width = 0;
  
      public MainPage()
      {
          this.InitializeComponent();
          this.Loaded += MainPage_Loaded;
          height = bounds.Height;
          width = -1 * bounds.Width;
      }
  </code></pre>
  
  <p>Let me know if there is an easy way. </p>