Setting Foreground for selected items.

Oct 13, 2008 at 8:21 PM
Edited Oct 15, 2008 at 2:51 AM

Hello,

I’m trying to set the selected item’s foreground to some color depending on some value in the object binded to. I had success setting the foreground for regular items, the problem is with the selected items.<o:p></o:p>

<my:DataGrid Name="lvEmployees" ItemsSource="{Binding}" Height="301" Canvas.Left="6" Canvas.Top="80" Width="724" AutoGenerateColumns="False" CanUserAddRows="False">

        <my:DataGrid.Resources>

          <myApplication:EmployeeRowColorConverter x:Key="rowColorConverter"/>

          <Style TargetType="my:DataGridRow" >

            <Setter Property="Foreground" Value="{Binding Path=IsPermanentEmployee, Converter={StaticResource rowColorConverter}}" />

            <Style.Triggers>

              <Trigger Property="IsSelected" Value="True" >

                <Setter Property="Foreground" Value="{Binding Path=IsPermanentEmployee, Converter={StaticResource rowColorConverter}}" " />

              </Trigger>

            </Style.Triggers>

          </Style>

        </my:DataGrid.Resources>

        <>          

        </>

      </my:DataGrid>

The code I’m having problem with is:

<Trigger Property="IsSelected" Value="True" >               

                <Setter Property="Foreground" Value="{Binding Path=IsPermanentEmployee, Converter={StaticResource rowColorConverter}}" " />

              </Trigger>

Moreover, setting the value to some static value, for example “Yellow” doesn’t work either. That’s something that doesn’t work either in any list control in WPF. Am I doing something wrong?

Trying something else, when I change the Resource “HighlightTextBrushKey” all the selected items change to that color, but I can’t do it in a conditional way.

Thank you in advance,

Ajadex.

Coordinator
Oct 14, 2008 at 1:26 PM
It may be possible that the DataGridCells are overriding the foreground color.  Try setting the style trigger on DataGridCell.IsSelected instead.
Oct 15, 2008 at 2:40 AM
Thank you very much vinsibal, it worked very well that way.