xaml - ListViewItem 选择颜色覆盖

标签 xaml windows-runtime

我需要覆盖 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 颜色,我在此处添加了一些注释,以便您可以看到哪个画笔执行什么操作:

enter image description here

enter image description here

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

相关文章:

c# - 在 ListView 的 gridview 中使用空格/输入选中/取消选中复选框 - wpf

c# - 不同计算机上的 WPF 应用程序不显示窗口

c# - 如何在W10的不同屏幕上正确适配应用程序UI

windows - 从开始屏幕而不是桌面运行 Delphi 应用程序需要什么 API

c++ - PPL 任务何时在 UI 线程上执行?

c# - 如何将图像放置在其中心而不是左上角?

wpf - Visual Studio 2012 XAML 设计器 - 不能添加多个项目

WPF ContentControl 宽度会增加,但在包裹在 ScrollViewer 中时不会缩小

c# - 在 WinRT 中从代码隐藏激活底部 AppBar

c# - 使用itextsharp使用哪个xaml控件显示pdf文件?