title: WPF Databinding DataTrigger to change color of shape based on boolean value
body: <p>I am trying to change the color of a shape by means of databinding and data trigger. </p>
  
  <p>But i am still new to WPF and all. </p>
  
  <p>Let me illustrate with an example. this is a group box  </p>
  
  <pre><code>&lt;GroupBox x:Class="Server.Host.SingleAxisControls"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:host="clr-namespace:Server.Host"
           mc:Ignorable="d" 
           d:DesignWidth="200"&gt;
      &lt;Grid&gt;
          &lt;StackPanel Orientation="Vertical" Width="180" &gt;
              &lt;host:MyRectangleControl x:Name="MyRectangle" /&gt;
              &lt;Button Click="OnButton_Click" Width="80" Margin="20,5,20,5"&gt;On&lt;/Button&gt;
              &lt;Button Click="OffButton_Click" Width="80"&gt;Off&lt;/Button&gt;
          &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  &lt;/GroupBox&gt;
  </code></pre>
  
  <p>MyRectangleControl is a usercontrol of something like</p>
  
  <pre><code>&lt;UserControl x:Class="Server.Host.MyRectangleControl"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           mc:Ignorable="d" 
           d:DesignHeight="30" d:DesignWidth="30"&gt;
  &lt;Grid&gt;
      &lt;Rectangle  HorizontalAlignment="Center"
                Height="25"
                Margin="0,0,0,0"
                Stroke="Black"
                VerticalAlignment="Center"
                Width="25" 
                Fill="red"&gt;
          &lt;Rectangle.Style&gt;
              &lt;Style TargetType="Rectangle"&gt;
                  &lt;Style.Triggers&gt;
                      &lt;DataTrigger Binding="{Binding Path=Test,UpdateSourceTrigger=PropertyChanged}"
                                   Value="True"&gt;
                          &lt;Setter Property="Fill"
                                  Value="Green" /&gt;
                      &lt;/DataTrigger&gt;
                  &lt;/Style.Triggers&gt;
              &lt;/Style&gt;
          &lt;/Rectangle.Style&gt;
      &lt;/Rectangle&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>In the code behind the groupbox, I have something like </p>
  
  <pre><code>namespace Server.Host
  {
  public partial class SingleAxisControls : INotifyPropertyChanged
  {
      public SingleAxisControls()
      {
          InitializeComponent();
  
          MyRectangle.DataContext = this;
      }
  
      private bool _test;
      public bool Test
      {
          get { return _test; }
          set
          {
              _test = value;
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs("Test"));
              }
          }
      }
  
      private void OnButton_Click(object sender, RoutedEventArgs e)
      {
          Test = true;
      }
  
      private void OffButton_Click(object sender, RoutedEventArgs e)
      {
          Test = false;
      }
  }
  </code></pre>
  
  <p>I am not sure what is wrong but it doesn't seem change the color of the rectangle when i change the value of test from false to true.</p>