title: How can I bind a background color in WPF dynamically?
body: <p>I cannot bind the background dynamically because it raises exception " A 'DynamicResourceExtension' cannot be set on the 'Source' property of type 'Binding'. A 'DynamicResourceExtension' can only be set on a DependencyProperty of a DependencyObject."</p>
  
  <pre><code>&lt;Window x:Class="TestWpfApplication.Window2"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:TestWpfApplication"
      mc:Ignorable="d"
      Title="Window2" Height="300" Width="300"&gt;
  &lt;Window.Resources&gt;
      &lt;SolidColorBrush Color="Blue" x:Key="customColorBrush"/&gt;
  &lt;/Window.Resources&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition/&gt;
          &lt;RowDefinition/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Button Background="{Binding Source={DynamicResource customColorBrush}}" Margin="20"&gt;&lt;/Button&gt;
      &lt;Button Background="{Binding Source={StaticResource customColorBrush}}" Margin="20" Grid.Row="1" Click="Button_Click"&gt;&lt;/Button&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>