2013-02-14 144 views
2

我需要覆盖ListViewItem的预定义样式,使其没有可见的选择。我知道如何将整个样式复制到我的资源中并进行编辑。但我不相信没有比复制整个风格更轻的方式。 所以我发现默认的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> 

注:我已经把所有的刷子我的用户,以及他们都设置为黄色。但我的UI中没有任何黄色,唉。 所以问题是:我如何强制默认模板使用我的重写刷? 第二个(可选)问题:也许我做错了,有更好的方法来实现我的目标?

回答

4

由于Vasile说您需要重写画笔,所以必须在应用程序级别完成,据我所知,如果您只想更改一个控件或在一个页面上,您需要对整个控件进行模板设置。

如果你好奇,你可以找到所有下刷: C:\ Program Files文件(x86)的\的Windows套件\ 8.0 \包含\的WinRT \ XAML中\设计

要覆盖ListView的颜色添加这在你的App.xaml /资源字典,我已经在这里添加了一些评论,所以你可以看到哪些画笔做什么:

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

谢谢,但应用广泛刷设置真的不是我的选择。如果没有其他选择,我会接受它作为答案,但。 – ixSci 2013-02-14 10:34:49

+0

我刚刚在设置页面出现了这个问题,并且我在MSDN上发现了一个线程,Tim Heuer回复说,只刷写页面的刷子是不可能的,仅适用于app.xaml。该线程于11月最后更新。不禁想到一定有办法.. – 2013-02-14 12:24:30

0

我一直在尝试类似的东西,没有运气。我想你只需要更新整个模板。

4

你必须重写他们在App.xaml文件,这样的事情(至少这是我如何做):

<ResourceDictionary.ThemeDictionaries> 
    <ResourceDictionary x:Key="Default"> 
     <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBorderThemeBrush" Color="Transparent" /> 
     <SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="Transparent" /> 
     <SolidColorBrush x:Key="ListViewItemSelectedPointerOverBackgroundThemeBrush" Color="Transparent" /> 
     <SolidColorBrush x:Key="ListViewItemSelectedBackgroundThemeBrush" Color="Transparent" /> 
    </ResourceDictionary> 
</ResourceDictionary.ThemeDictionaries> 

如果您需要更多的自定义(在我的ListView的项目是一些图片) ,这是一个非常有用的链接,用于更改默认的Color Controls

1

在Windows 8.1通用的应用程序共享App.xaml中我使用此代码

<Application 
    x:Class="XXX.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:XXX"> 

    <Application.Resources> 
     <ResourceDictionary> 
      <SolidColorBrush x:Key="ListViewItemPointerOverBackgroundThemeBrush" Color="Transparent" /> 
     </ResourceDictionary> 
    </Application.Resources> 
</Application>