title: How can I change the Foreground color of a TextBlock with a Trigger?
body: <p>I want to change foreground color of a TextBlock from dependencyproperty.<br>
  But I don't change textblock color.<br>
  I don't know this problem in my code.<br>
  How can I change the foreground color of a TextBlock with a Trigger?<br></p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;TextBlock Name="TestBlock" Text="Test color" &gt;
      &lt;TextBlock.Style&gt;
          &lt;Style TargetType="TextBlock"&gt;
              &lt;Style.Triggers&gt;
                  &lt;Trigger Property ="IsMouseOver" Value="True"&gt;
                      &lt;Setter Property= "Foreground" Value="Gray"/&gt;
                  &lt;/Trigger&gt;
                  &lt;DataTrigger Binding="{Binding Path=TestColorMode2, RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}}" Value="0"&gt;
                      &lt;Setter Property="Foreground" Value="Red" /&gt;
                  &lt;/DataTrigger&gt;
                  &lt;DataTrigger Binding="{Binding Path=TestColorMode2, RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}}" Value="1"&gt;
                      &lt;Setter Property="Foreground" Value="Blue" /&gt;
                  &lt;/DataTrigger&gt;
                  &lt;DataTrigger Binding="{Binding Path=TestColorMode2, RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}}" Value="2"&gt;
                      &lt;Setter Property="Foreground" Value="Green" /&gt;
                  &lt;/DataTrigger&gt;
                  &lt;DataTrigger Binding="{Binding Path=TestColorMode2, RelativeSource={RelativeSource AncestorType={x:Type local:Window1}}}" Value="3"&gt;
                      &lt;Setter Property="Foreground" Value="Black" /&gt;
                  &lt;/DataTrigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
      &lt;/TextBlock.Style&gt;
  &lt;/TextBlock&gt;
  </code></pre>
  
  <p><strong>CODE:</strong></p>
  
  <pre><code>public static DependencyProperty TestColorModeProperty = DependencyProperty.Register("TestColorMode", typeof(int), typeof(UpdateProgressItem));
  
  public int TestColorMode
  {
      get { return (int)GetValue(TestColorModeProperty); }
      set { SetValue(TestColorModeProperty, value); }
  }
  
              ....
  
  private void button1_Click(object sender, RoutedEventArgs e)
  {
      TestColorMode++;
  }
  </code></pre>