title: Getting the Background of a UIElement or sender
body: <p>I'm trying to find a generic way to set the Background property on a UIElement.</p>
  
  <p>I'm not having much luck...</p>
  
  <p>Here's what I have so far (trying to use reflection to get the BackgroundProperty).</p>
  
  <pre><code>  Action&lt;UIElement&gt; setTheBrushMethod = (UIElement x) =&gt;
    {
      var brush = new SolidColorBrush(Colors.Yellow);
      var whatever = x.GetType().GetField("BackgroundProperty");
      var val = whatever.GetValue(null);
      ((UIElement)x).SetValue(val as DependencyProperty, brush);
      brush.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation(Colors.White, TimeSpan.FromSeconds(3)));
    };
    setTheBrushMethod(sender as UIElement);
  </code></pre>
  
  <p>The thing is...it works for something like a TextBlock, but does not work for something like a StackPanel or a Button.</p>
  
  <p>"whatever" ends up being null for StackPanel or Button.</p>
  
  <p>I also feel like there should be an easy way to generically set the Background.  Am I missing obvious?</p>
  
  <p>Background only appears to be available on System.Windows.Controls.Control but I can't cast to that.</p>