HighlightBrushKey设置在Windows 7中不起作用 [英] HighlightBrushKey settings not working in Windows 7

查看:98
本文介绍了HighlightBrushKey设置在Windows 7中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在资源字典中定义了以下样式:

I have the following style defined in my 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-->

当我使用Windows XP时,我得到的行为是我的渐变用于Hightlight和选择.现在我已经切换到使用Windows 7,似乎不再使用渐变了,突出显示/选择的颜色现在变成了VS外观的浅蓝色.

When i was using windows XP the behavior that I was getting was my gradients were used for the Hightlight and the selection. Now i have switched over to using Windows 7 and it seems like the gradients are no longer used the highlight/selection colors are now the light blue of the VS look.

关于为什么会发生这种情况以及如何以在Windows XP和Windows 7(我们拥有多平台环境)下都能正常使用的方式解决此问题的任何建议

Any suggestions on why this would be happening and how do I fix this in such a way that it works the same on Windows XP and Windows 7 (we have a multiplatform environment)

谢谢.

评论后的完整解决方案

<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>

推荐答案

Aero上的默认样式与Luna主题略有不同.在Aero中,默认样式为:

The default Style on Aero is a bit different then the Luna themes. In Aero, there is a trigger like so in the default Style:

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

在Luna上,它看起来像:

While on Luna, it looks like:

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

因此您可以看到Aero的默认样式,根本不使用HighlightBrushKey.这主要是因为这些笔刷基于单一的纯色.但是Aero主题有很多渐变,不能用旧样式的颜色来表示.

So you can see the default Style for Aero, doesn't use the HighlightBrushKey at all. This is mostly because those brushes are based on a single solid color. But the Aero theme has a lot of gradients, which can't be represented by the old style colors.

您还需要设置Background属性,以将其应用于Aero,就像这样:

You would need to set the Background property as well to apply it on Aero, like so:

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

这篇关于HighlightBrushKey设置在Windows 7中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆