Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

ListBox item selected foreground color not working if initial foreground color altered. What am I missing???

$
0
0

Hello,

I have a ListBox where I needed some of my items listed and red and the rest in the normal black.  I was able to do that by adding the following:

 <ListBox.Resources>
      <DataTemplate DataType="{x:Type ViewModels:IngestGroup}">
            <TextBlock Text="{Binding Path=name}">
                 <TextBlock.Foreground>
                       <SolidColorBrush Color="{Binding Path=color}"/>
                 </TextBlock.Foreground>
            </TextBlock>
       </DataTemplate>
 </ListBox.Resources>

All is well with that.  When an item is selected, however, the normal selected foreground color of white is not used.  The foreground color remains either black or red.  So, I tried to add the following to give me the white foreground on the selected node:

<ListBox.ItemContainerStyle>
     <Style TargetType="ListBoxItem">
           <Style.Triggers>
                <Trigger Property="IsSelected" Value="True" >
                    <Setter Property="Foreground" Value="White" />
                </Trigger>
           </Style.Triggers>
     </Style>
</ListBox.ItemContainerStyle>

This has no effect and the selected foreground color is never changed. When I leave this code and remove the <ListBox.Resources> entry, the trigger DOES chnage the foreground color to the designated value. I tried this using various colors since white is the default.

Does anyone know why the trigger setter property is not changed when the ListBox initially sets text color via the <DataTemplate>??  Is there a different way I should be doing this.

Thanks - Peter


Viewing all articles
Browse latest Browse all 18858

Trending Articles