HighlightBrushKey settings not working on Windows 7

I have the following style defined in the resource dictionary:

<!-- ListViewItem Styles--> <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#F7D073" Offset="0"/> <GradientStop Color="#F1A62F" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <LinearGradientBrush x:Key="{x:Static SystemColors.ControlBrushKey}" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#F7D073" Offset="0"/> <GradientStop Color="#F1A62F" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <LinearGradientBrush x:Key="MouseOverBrush" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#E4F0FD" Offset="0"/> <GradientStop Color="#D7EAFD" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <Style TargetType="{x:Type ListViewItem}"> <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataForeground, Converter={StaticResource ColorToBrushConverter}}" /> <Setter Property="Padding" Value="1,0,1,0" /> <Setter Property="FontWeight" Value="Normal" /> <Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderBrush" Value="Transparent"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background" Value="{StaticResource MouseOverBrush}" /> <Setter Property="BorderBrush" Value="#C6E1FC" /> <Setter Property="BorderThickness" Value="1" /> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Foreground" Value="Black" /> <Setter Property="BorderBrush" Value="#909090" /> <Setter Property="BorderThickness" Value="1" /> </Trigger> </Style.Triggers> <Style.Resources> <Style TargetType="Border"> <Setter Property="CornerRadius" Value="2"/> </Style> </Style.Resources> </Style> <!-- /ListViewItem Styles--> 

When I used Windows XP, the behavior I was getting was my gradient, which was used for Hightlight and selection. Now I switched to using Windows 7, and it seems that gradients are no longer used, the highlight / select colors are now VS blue.

Any suggestions on why this is happening, and how I can fix it so that it works the same on Windows XP and Windows 7 (we have a multi-platform environment)

Thanks.

Complete solution after comments

 <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#F7D073" Offset="0"/> <GradientStop Color="#F1A62F" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <LinearGradientBrush x:Key="{x:Static SystemColors.ControlBrushKey}" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#F7D073" Offset="0"/> <GradientStop Color="#F1A62F" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <LinearGradientBrush x:Key="MouseOverBrush" StartPoint="0,0" EndPoint="0,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#E4F0FD" Offset="0"/> <GradientStop Color="#D7EAFD" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <Style TargetType="{x:Type ListViewItem}"> <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataForeground, Converter={StaticResource ColorToBrushConverter}}" /> <Setter Property="Padding" Value="1,0,1,0" /> <Setter Property="FontWeight" Value="Normal" /> <Setter Property="BorderThickness" Value="1"/> <Setter Property="BorderBrush" Value="Transparent"/> <Style.Triggers> <Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background" Value="{StaticResource MouseOverBrush}" /> <Setter Property="BorderBrush" Value="#C6E1FC" /> <Setter Property="BorderThickness" Value="1" /> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <Setter Property="Foreground" Value="Black" /> <Setter Property="BorderBrush" Value="#909090" /> <Setter Property="BorderThickness" Value="1" /> </Trigger> <!-- This part of the triger is for when Windows Aero theme is turned on Win Vista/7--> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem}, Path=IsSelected}" Value="True" /> <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}, Path=IsKeyboardFocusWithin}" Value="True" /> </MultiDataTrigger.Conditions> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <Setter Property="Foreground" Value="Black" /> <Setter Property="BorderBrush" Value="#909090" /> <Setter Property="BorderThickness" Value="1" /> </MultiDataTrigger> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListViewItem}, Path=IsSelected}" Value="True" /> <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}, Path=IsKeyboardFocusWithin}" Value="False" /> </MultiDataTrigger.Conditions> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <Setter Property="Foreground" Value="Black" /> <Setter Property="BorderBrush" Value="#909090" /> <Setter Property="BorderThickness" Value="1" /> </MultiDataTrigger> </Style.Triggers> <Style.Resources> <Style TargetType="Border"> <Setter Property="CornerRadius" Value="2"/> </Style> </Style.Resources> </Style> 
+4
source share
1 answer

The default style on Aero is slightly different from Luna's. Aero has a default trigger like this:

 <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" Value="{StaticResource ListItemSelectedFill}"/> <!-- ... --> </Trigger> 

So far on Luna it looks like this:

 <Trigger Property="IsSelected" Value="true"> <Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <!-- ... --> </Trigger> 

So you can see the default style for Aero, don't use HighlightBrushKey at all. This is mainly because these brushes are based on one solid color. But the Aero theme has many gradients that cannot be represented by old-style colors.

You will need to set the Background property, and apply it to Aero, for example:

 <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <!-- ... --> </Trigger> 
+4
source

All Articles