title: WPF styling TabControl TabItems custom Foreground/Background colors
body: <p>I'm pretty new to WPF -- tantalized by the possibilities, but getting frustrated.... I'm trying to make it so different tabs on a TabControl have different foregound/background colors according to when they're selected. First thing I did was to create new TabItem class called PlayerTabItem and gave it a Brush SelectedBackground property. This is a music player app, so "player" in this context refers to its use in this app. (I first created SelectedBackground as a simple property, then later as a dependency property, but this didn't seem to change anything, so I have omitted that implementation.)</p>
  
  <pre class="lang-c prettyprint-override"><code>class PlayerTabItem : TabItem
  {
      public Brush SelectedBackground { get; set; }
  }
  </code></pre>
  
  <p>Then I used this is in my XAML, and it compiled okay (so long as I put "local:" in front of the tag name), and recognized the new property I created. Of course, the property didn't do anything. This is where I got stuck.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;local:PlayerTabItem Header="Now Playing" SelectedBackground="Blue"/&gt;
  &lt;local:PlayerTabItem Header="Collection" SelectedBackground="Purple"/&gt;
  &lt;local:PlayerTabItem Header="Search" SelectedBackground="Green"/&gt;
  </code></pre>
  
  <p>I tried handling selection events in the PlayerTabItem class in order to apply the background color, but this was a dead end. (Overriding PlayerTabItem.OnSelected and setting color there had no effect -- ran without error but did nothing.) Then I tried adding a Style with a new ControlTemplate and a Trigger for IsSelected = true, and I started getting closer....it worked if I just hard-coded a color in the Trigger.Setter:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Trigger Property="IsSelected" Value="True"&gt;
     &lt;Setter TargetName="Panel" Property="Background" Value="Purple" /&gt;
  &lt;/Trigger&gt;
  </code></pre>
  
  <p>But what I really want is to bind to the PlayerTabItem's SelectedBackground color. I tried this:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;Setter TargetName="Panel" Property="Background" Value="{Binding SelectedBackground}" /&gt;
  </code></pre>
  
  <p>But it had no effect. I suspected that I needed some kind of Path argument on the binding, but I had no idea what. I tried using XAMLSpy to maybe help me see what was going on (as far as hierarchy of elements and possible binding path), but I didn't get very far with that -- except that when I tried to set the SelectedBackground property through XAMLSpy, it reported that the property SelectedBackground wasn't found. How could that be? ....since I had compiled and run the program without error.</p>
  
  <p>I hope what I'm trying to do makes sense -- I just want to change the background color of selected tabs on a tab control when they are selected.</p>