title: Foreground issue when using with Dynamic resource
body: <p>For my custom control, I am using the Dynamic resource to set the Foreground property. Initially when i run the app the Foreground property was not set to my control. When I change value dynamically Foreground was applied correctly. How can I resolve this issue?</p>
  
  <p>PS: Simple sample <a href="http://www75.zippyshare.com/v/76242743/file.html" rel="nofollow">WpfApplication4</a></p>
  
  <p>MainWindow.xaml</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication4.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow"
      Width="300"
      Height="200"&gt;
  &lt;Window.Resources&gt;
      &lt;SolidColorBrush x:Key="ForegroundBrush" Color="Red" /&gt;
      &lt;SolidColorBrush x:Key="BackgroundBrush" Color="Yellow" /&gt;
  
      &lt;Style x:Key="MyStyle" TargetType="ContentControl"&gt;
          &lt;Setter Property="Foreground" Value="{DynamicResource ForegroundBrush}" /&gt;
          &lt;Setter Property="Background" Value="{DynamicResource BackgroundBrush}" /&gt;
      &lt;/Style&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="Auto" /&gt;
          &lt;RowDefinition Height="*" /&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;StackPanel&gt;
          &lt;Button Click="ButtonBase_OnClick" Content="Create and Add Custom Control With Style" /&gt;
          &lt;Button Click="ButtonBase_OnClick_1" Content="Change Color" /&gt;
      &lt;/StackPanel&gt;
      &lt;StackPanel x:Name="myPanel" Grid.Row="1" /&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>MainWindow.xaml.cs</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
      {
          var control = new MyControl {Style = this.Resources["MyStyle"] as Style};
          control.CreateContent(string.Format("My Control {0}", myPanel.Children.Count + 1));
          myPanel.Children.Add(control);
      }
  
      private void ButtonBase_OnClick_1(object sender, RoutedEventArgs e)
      {
          var brush = (SolidColorBrush)Resources["ForegroundBrush"];
          Resources["ForegroundBrush"] = new SolidColorBrush(Color.Add(brush.Color, Color.FromRgb(0, 100, 100)));
  
          var brush1 = (SolidColorBrush)Resources["BackgroundBrush"];
          Resources["BackgroundBrush"] = new SolidColorBrush(Color.Add(brush1.Color, Color.FromRgb(0, 100, 100)));
      }
  }
  
  public class MyControl : ContentControl
  {
      public MyControl()
      {
          DefaultStyleKey = typeof(MyControl);
      }
  
      public void CreateContent(string text)
      {
          this.Content = new TextBlock() {Text = text};
      }
  }
  </code></pre>
  
  <p>Generic.xaml</p>
  
  <pre><code>&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:local="clr-namespace:WpfApplication4"&gt;
  &lt;Style TargetType="local:MyControl"&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="local:MyControl"&gt;
                  &lt;Border Background="{TemplateBinding Background}"&gt;
                      &lt;ContentPresenter Content="{TemplateBinding Content}" /&gt;
                  &lt;/Border&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p></p>