title: Changing the Foreground colour of a contentpresenter in a listbox
body: <p>I have created the following style for a listbox that will have an image displayed next to some text:</p>
  
  <pre><code>&lt;Style x:Key="ImageListBoxStyle" TargetType="{x:Type ListBox}"&gt;
      &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt;
      &lt;Setter Property="BorderThickness" Value="1"/&gt;
      &lt;Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/&gt;
      &lt;Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/&gt;
      &lt;Setter Property="ScrollViewer.CanContentScroll" Value="True"/&gt;
      &lt;Setter Property="ItemContainerStyle"&gt;
          &lt;Setter.Value&gt;
              &lt;!-- Simple ListBoxItem - This is used for each Item in a ListBox. The item's content is placed in the ContentPresenter --&gt;
              &lt;Style TargetType="{x:Type ListBoxItem}"&gt;
                  &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt;
                  &lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt;
                  &lt;Setter Property="VerticalContentAlignment" Value="Center"/&gt;
                  &lt;Setter Property="Template"&gt;
                      &lt;Setter.Value&gt;
                          &lt;ControlTemplate TargetType="{x:Type ListBoxItem}"&gt;
                              &lt;Grid SnapsToDevicePixels="true"&gt;
                                  &lt;Border x:Name="Border"&gt;
                                      &lt;Grid Height="40"&gt;
                                          &lt;Grid.ColumnDefinitions&gt;
                                              &lt;ColumnDefinition Width="Auto"/&gt;
                                              &lt;ColumnDefinition Width="*"/&gt;
                                          &lt;/Grid.ColumnDefinitions&gt;
                                          &lt;Image
                                              x:Name="DisplayImage"
                                              Source="{Binding Path=ThumbnailImage}"
                                              Height="30"
                                              Width="30"
                                              Grid.Column="0"/&gt;
  
                                          &lt;ContentPresenter
                                              x:Name="DisplayText"
                                              HorizontalAlignment="Stretch"
                                              VerticalAlignment="Center"
                                              Grid.Column="1"/&gt;
                                          &lt;!--&lt;ContentPresenter.Resources&gt;
                                                  &lt;Style TargetType="{x:Type TextBlock}"&gt;
                                                      &lt;Setter Property="Foreground" Value="Black"/&gt;
                                                  &lt;/Style&gt;
                                              &lt;/ContentPresenter.Resources&gt;--&gt;
  
                                          &lt;!--Content="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}, Path=DisplayMemberPath, Converter={StaticResource myDisplayMemberConverter}}"--&gt;
                                          &lt;!--&lt;Label
                                              x:Name="Text"
                                              Content="{Binding Path=FullNameAndTitle}"
                                              Foreground="Black"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              VerticalContentAlignment="Center"
                                              HorizontalAlignment="Stretch"
                                              Grid.Column="1"
                                              Height="40"/&gt;--&gt;
                                      &lt;/Grid&gt;
                                  &lt;/Border&gt;
                              &lt;/Grid&gt;
                              &lt;ControlTemplate.Triggers&gt;
                                  &lt;Trigger Property="IsSelected" Value="true"&gt;
                                      &lt;!--&lt;Setter Property="FontWeight" Value="Bold" TargetName="DisplayText"/&gt;--&gt;
                                      &lt;!--&lt;Setter Property="Style" Value="{StaticResource SelectedTextStyle}" TargetName="DisplayText"/&gt;--&gt;
                                      &lt;Setter Property="Background" Value="DarkBlue" TargetName="Border"/&gt;
                                      &lt;Setter Property="Width" Value="40" TargetName="DisplayImage"/&gt;
                                      &lt;Setter Property="Height" Value="40" TargetName="DisplayImage"/&gt;
                                  &lt;/Trigger&gt;
                              &lt;/ControlTemplate.Triggers&gt;
                          &lt;/ControlTemplate&gt;
                      &lt;/Setter.Value&gt;
                  &lt;/Setter&gt;
              &lt;/Style&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
      &lt;Setter Property="Template"&gt;
          &lt;Setter.Value&gt;
              &lt;ControlTemplate TargetType="{x:Type ListBox}"&gt;
                  &lt;Grid&gt;
                      &lt;Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="Black" BorderThickness="{TemplateBinding BorderThickness}"&gt;
                          &lt;Grid&gt;
                              &lt;ScrollViewer Margin="1,1,1,1" Focusable="false" Background="{TemplateBinding Background}" SnapsToDevicePixels="True"&gt;
                                  &lt;StackPanel IsItemsHost="true"/&gt;
                              &lt;/ScrollViewer&gt;
                          &lt;/Grid&gt;
                      &lt;/Border&gt;
                  &lt;/Grid&gt;
                  &lt;ControlTemplate.Triggers&gt;
                      &lt;Trigger Property="IsGrouping" Value="true"&gt;
                          &lt;Setter Property="ScrollViewer.CanContentScroll" Value="false"/&gt;
                      &lt;/Trigger&gt;
                  &lt;/ControlTemplate.Triggers&gt;
              &lt;/ControlTemplate&gt;
          &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>I have to use the contentpresenter as I am filtering what is displayed (text wise) using the DisplayMemberPath of the ListBox itself.</p>
  
  <p>All I want to do is set the FontWeight to Bold and the Foreground to White when an item is selected in the ListBox.</p>
  
  <p>Has anyone encountered a problem like this? I have looked at some related questions but people have been able to use a TextBlock to get around their issues I can't unfortunately.</p>
  
  <p>Any info ppl can give will be appreciated.</p>
  
  <p>Cheers</p>