title: Running a ColorAnimation with a To value from a static class
body: <p>I'm trying to solve a problem where I am running a ColorAnimation in a storyboard and the "To" value can only be provided by a static class.</p>
  
  <p>Basically, the desired outcome is:</p>
  
  <pre><code>&lt;ColorAnimation BeginTime="0:00:00" Duration="0:00:00.333"
    Storyboard.TargetName="border"
    Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"
    To="{Binding XYZ, Source={x:Static ZZZ}}" /&gt;
  </code></pre>
  
  <p>Obviously this will crash since bindings can't be placed in a ColorAnimation's To value. I would consider making a duplicate of the static class's property in the ControlTemplate resources so that a {StaticResource} may be used instead:</p>
  
  <pre><code>&lt;ControlTemplate.Resources&gt;
    &lt;Color x:Key="animation_to_value"&gt;{Binding ...}&lt;/Color&gt;
  &lt;/ControlTemplate.Resource&gt;
  </code></pre>
  
  <p>I'm not sure if this is possible or what the correct syntax would be.</p>
  
  <p>The final solution I have considered is to insert the color resources in to App.xaml's resource dictionary at runtime in the code-behind and refactoring the storyboard to a separate resource dictionary and merging it at runtime, so the static resources are resolved after the colors have been inserted:</p>
  
  <pre><code>public App()
  {
    this.Resources["storyboard_to_value"] = Colors.Red;
    this.Resources.MergedDictionaries.Add(GetDictionaryWithStoryboard());
  }
  </code></pre>
  
  <p>This seems overkill though. Please advise.</p>