wpf – HighlightBrushKey设置在Windows 7中不起作用
发布时间:2020-12-14 05:30:32 所属栏目:Windows 来源:网络整理
导读:我的资源字典中定义了以下样式: !-- ListViewItem Styles--LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,0" EndPoint="0,1" LinearGradientBrush.GradientStops GradientStopCollection GradientStop Color="#F7D
我的资源字典中定义了以下样式:
<!-- 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,1"> <LinearGradientBrush.GradientStops> <GradientStopCollection> <GradientStop Color="#F7D073" Offset="0"/> <GradientStop Color="#F1A62F" Offset="1"/> </GradientStopCollection> </LinearGradientBrush.GradientStops> </LinearGradientBrush> <LinearGradientBrush x:Key="MouSEOverBrush" StartPoint="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,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时,我得到的行为是我的渐变用于高光和选择.现在我已经切换到使用Windows 7,似乎渐变不再使用高亮/选择颜色现在是VS外观的浅蓝色. 有关为什么会发生这种情况的任何建议,以及如何以在Windows XP和Windows 7上运行相同的方式解决此问题(我们有一个多平台环境) 谢谢. 评论后的完整解决方案 <LinearGradientBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" StartPoint="0,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,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中,默认样式中有一个类似的触发器:
<Trigger Property="IsSelected" Value="true"> <Setter Property="Background" Value="{StaticResource ListItemSelectedFill}"/> <!-- ... --> </Trigger> 在Luna上,它看起来像: <Trigger Property="IsSelected" Value="true"> <Setter TargetName="Bd" Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <!-- ... --> </Trigger> 因此,您可以看到默认的Aero风格,根本不使用HighlightBrushKey.这主要是因为这些画笔基于单一纯色.但是Aero主题有很多渐变,不能用旧式的颜色来表示. 您还需要设置Background属性以将其应用于Aero,如下所示: <Trigger Property="IsSelected" Value="true"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> <!-- ... --> </Trigger> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Windows环境搭建ElasticSearch 集群
- reactjs – jest没有实现window.alert()
- windows环境下的Anaconda安装与OpenCV机器视觉环境搭建
- 如何在Windows上为C中的访问冲突错误安装信号处理程序?
- windows-server-2008 – 如何启用命令行远程访问Windows Se
- 从Windows 10主机将USB Android设备挂载到Docker容器
- 在Windows下编译适用于PHP 5.2.12及5.2.13的eAccelerator.d
- 默认情况下,Windows XP中安装了哪些编程语言
- windows10 安装python.msi出现error 2502/2503解决方法
- Windows Azure Powershell部署错误 – “远程服务器返回了意
推荐文章
站长推荐
- 内存 – x64 Windows报告安装了64GB RAM的32GB R
- windows-server-2008 – “Net Send”命令进入Mi
- windows – 屏幕录制
- 如何在Windows上使用PyPy?
- windows-server-2008 – Perfmon – 无法启动数据
- compact-framework – 无法加载DLL’coredll.dll
- 使用windows/dos shell/batch命令,如何获取文件并
- 丢失libiconv-2.dll解决办法以及无法定位输入点l
- .net – 如何避免Windows窗体单选按钮容器自动分
- windows – powershell脚本和subst命令
热点阅读