title: Updating a style trigger in code in WPF?
body: <p>I have a XAML with a StackPanel and various TextBlocks inside it that I'm using as a menu:</p>
  
  <pre><code>&lt;StackPanel Width="200" DockPanel.Dock="Left" Background="CornflowerBlue"&gt;
  &lt;StackPanel.Style&gt;
      &lt;Style TargetType="StackPanel"&gt;
          &lt;Style.Resources&gt;
              &lt;Style TargetType="TextBlock"&gt;
                  &lt;Setter Property="Cursor" Value="Hand" /&gt;
                  &lt;Setter Property="Foreground" Value="White" /&gt;
  
                  &lt;Style.Triggers&gt;
                      &lt;Trigger Property="IsMouseOver" Value="True"&gt;
                          &lt;Setter Property="Foreground" Value="Gold" /&gt;
                      &lt;/Trigger&gt;
  
                      &lt;Trigger Property="Tag" Value="1"&gt;
                          &lt;Setter Property="Foreground" Value="Black" /&gt;
                          &lt;Setter Property="Background" Value="WhiteSmoke" /&gt;
                      &lt;/Trigger&gt;
                  &lt;/Style.Triggers&gt;
              &lt;/Style&gt;
          &lt;/Style.Resources&gt;
      &lt;/Style&gt;
  &lt;/StackPanel.Style&gt;
  
  &lt;TextBlock Padding="10" FontWeight="Bold" FontSize="15" MouseDown="TextBlock_MouseDown"&gt;
      &lt;TextBlock.InputBindings&gt;
          &lt;MouseBinding Command="local:MainWindow.UserList" MouseAction="LeftClick" /&gt;
      &lt;/TextBlock.InputBindings&gt;
      &lt;TextBlock.Text&gt;
          USER LIST
      &lt;/TextBlock.Text&gt;
  &lt;/TextBlock&gt;
  
  &lt;TextBlock Padding="10" FontWeight="Bold" FontSize="15" MouseDown="TextBlock_MouseDown"&gt;                    
      &lt;TextBlock.InputBindings&gt;
          &lt;MouseBinding Command="local:MainWindow.Exit" MouseAction="LeftClick" /&gt;
      &lt;/TextBlock.InputBindings&gt;
      &lt;TextBlock.Text&gt;
          EXIT
      &lt;/TextBlock.Text&gt;
  &lt;/TextBlock&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>And in the code, I have this function:</p>
  
  <pre><code>private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
  {
      (sender as TextBlock).Tag = 1;
      //(sender as TextBlock).Tag = "1"; //Or this
  }
  </code></pre>
  
  <p>If I set the <code>Tag</code> in the XAML, the style is property updated, but this doesn't happen if I set the <code>Tag</code> in the code. I've also tried manually changing the <code>Background</code>/<code>Foreground</code> properties in the code but I'm guessing the XAML style is overwriting it.</p>
  
  <p>I'm trying to make it so that when the user clicks the textblock, the background/foreground (or whatever else the style requires) updates as well, 
  it's a "Selected" Menu option, but I can't get it working.</p>
  
  <p>Is there any simple way to get this working without having to write a custom control?</p>