title: How to control Textblock properties through TabControl template
body: <p>I have setup a <code>TabControl</code> with custom grid to hold a picture and a <code>Textblock</code> object as the design for the headers (<code>TabItem</code>). I am currently controlling the background colors of the headers with a template and I cannot figure out how to also control the <code>Foreground</code> color of the embedded <code>TextBlock</code> using the same template.</p>
  
  <p>I'm a novice Visual Studio C# guy, but my understanding of these Templates is that I can use them to set child properties as well (kind of similar to CSS child selectors)? Or am I completely off?</p>
  
  <p>Here's my "design" -- you'll notice the three tabs on top with custom styling:
  <a href="https://i.stack.imgur.com/x6F6T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/x6F6T.png" alt="Design with three tabs on top"></a></p>
  
  <p>My current template for the <code>TabItem</code>
  </p>
  
  <pre><code>&lt;Setter Property="Template"&gt;
  
      &lt;Setter.Value&gt;
          &lt;ControlTemplate TargetType="{x:Type TabItem}"&gt;
              &lt;Grid x:Name="Root"&gt;
                  &lt;Border x:Name="Border" Margin="0,0,-4,0"&gt;
                      &lt;ContentPresenter x:Name="ContentSite"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    ContentSource="Header"
                    Margin="12,2,12,2"
                    RecognizesAccessKey="True" /&gt;
  
                  &lt;/Border&gt;
  
              &lt;/Grid&gt;
              &lt;ControlTemplate.Triggers&gt;
                  &lt;!-- Selected color --&gt;
                  &lt;Trigger Property="IsSelected" Value="True"&gt;
                      &lt;!-- &lt;Setter Property="TextElement.Foreground" TargetName="ContentSite" Value="White"/&gt;--&gt;
                      &lt;Setter Property="Panel.ZIndex" Value="100" /&gt;
                      &lt;Setter TargetName="Border" Property="Background" Value="#FFEF690D" /&gt;
                  &lt;/Trigger&gt;
  
                  &lt;!-- Not Selected color --&gt;
                  &lt;Trigger Property="IsSelected" Value="False"&gt;
                      &lt;Setter TargetName="Border" Property="Background" Value="#FFEE8740" /&gt;
                  &lt;/Trigger&gt;
  
                  &lt;!-- Tab mouseovers--&gt;
                  &lt;MultiTrigger&gt;
                      &lt;MultiTrigger.Conditions&gt;
                          &lt;Condition Property="IsMouseOver" Value="True"/&gt;
                          &lt;Condition Property="IsSelected" Value="False"/&gt;
                      &lt;/MultiTrigger.Conditions&gt;
                      &lt;Setter TargetName="Border" Property="Background" Value="#FFEFA470" /&gt;
                  &lt;/MultiTrigger&gt;
  
              &lt;/ControlTemplate.Triggers&gt;
          &lt;/ControlTemplate&gt;
      &lt;/Setter.Value&gt;
  &lt;/Setter&gt;
  </code></pre>
  
  <p></p>
  
  <p>My current xaml setup for the <code>TabControl</code> (less the third <code>TabItem</code> for brevity)</p>
  
  <pre><code>&lt;TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="311" Margin="0" VerticalAlignment="Top" Width="717" Background="#FFF9F9F9" Style="{DynamicResource MainMenuTabs}"&gt;
    &lt;TabItem Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}"&gt;
          &lt;!-- TAB 1 --&gt;
          &lt;TabItem.Header&gt;
                &lt;Grid x:Name="Main" Margin="0" Height="52" Width="166"&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                            &lt;ColumnDefinition Width="52"/&gt;
                            &lt;ColumnDefinition/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;TextBlock x:Name="textBlock" Margin="0,5,0,3" TextWrapping="Wrap" Foreground="White" FontSize="36" Grid.Column="1" d:LayoutOverrides="Width" VerticalAlignment="Bottom"&gt;&lt;Run Text="Main"/&gt;&lt;/TextBlock&gt;
                      &lt;Image x:Name="icons_server_32_png" Margin="10,0,10,10" Source="icons/server-32.png" Stretch="Fill" Height="32" VerticalAlignment="Bottom"/&gt;
                &lt;/Grid&gt;
          &lt;/TabItem.Header&gt;
          &lt;Grid Background="#FFE5E5E5"/&gt;
    &lt;/TabItem&gt;
    &lt;TabItem&gt;
          &lt;!-- TAB 2 --&gt;
          &lt;TabItem.Header&gt;
                &lt;Grid x:Name="Backups" Margin="0" Height="52" Width="216"&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                            &lt;ColumnDefinition Width="52"/&gt;
                            &lt;ColumnDefinition/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
                      &lt;TextBlock x:Name="textBlock1" Margin="0,5,0,3" TextWrapping="Wrap" Foreground="White" FontSize="36" Grid.Column="1" d:LayoutOverrides="Width" VerticalAlignment="Bottom" Text="Backups"/&gt;
                      &lt;Image x:Name="icons_server_32_png1" Margin="10,0,10,10" Source="icons/magnifier-tool.png" Stretch="Fill" Height="32" VerticalAlignment="Bottom"/&gt;
                &lt;/Grid&gt;
          &lt;/TabItem.Header&gt;
          &lt;Grid Background="#FFE5E5E5"/&gt;
    &lt;/TabItem&gt;
  &lt;/TabControl&gt;
  </code></pre>