2013-02-14 234 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>