我需要覆盖 ListViewItem 的预定义样式以使选择不可见。如果我将整个样式复制到我的资源中并进行编辑,我知道该怎么做。但我不敢相信没有比复制整个样式更轻松的方法了。 所以我发现默认的 ListViewItem 样式使用以下画笔进行选择:
<UserControl.Resources>
<SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="Yellow" />
<SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="Yellow" />
<SolidColorBrush x:Key="ListViewItemSelectedForegroundThemeBrush" Color="Yellow" />
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="Yellow" />
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="Yellow" />
</UserControl.Resources>
注意:我已将所有这些画笔放到我的用户控件中,并将它们全部设置为黄色。但是我的用户界面中没有任何黄色,唉。 所以问题是:如何强制默认模板使用我覆盖的画笔? 第二个(可选)问题:也许我做错了,有更好的方法来实现我的目标吗?
最佳答案
正如 Vasile 所说,您需要覆盖画笔,这必须在 App 级别完成,据我所知,如果您只想更改一个控件或在一页上更改,则需要对整个控件进行模板化。
如果你好奇,你可以在下面找到所有的画笔: C:\Program Files (x86)\Windows Kits\8.0\Include\WinRT\Xaml\Design
要覆盖您在 App.xaml/resource 字典中添加的 ListView 颜色,我在此处添加了一些注释,以便您可以看到哪个画笔执行什么操作:
<ResourceDictionary x:Key="Default">
<!--After selection - Background-->
<SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="Yellow"></SolidColorBrush>
<!--When pointer hovers over an item - Background-->
<SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="Red"></SolidColorBrush>
<!--When the item is selected (first few milliseconds) - Background-->
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="Green"></SolidColorBrush>
<!--When the item is selected (first few milliseconds) - Border-->
<SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="Black"></SolidColorBrush>
</ResourceDictionary>
关于xaml - ListViewItem 选择颜色覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14868773/