2009-08-09 91 views
8

我有WPF ListView與GridView視圖,我想刪除任何行高亮的痕跡。刪除WPF ListView/GridView突出顯示鉻

這有用的代碼塊可以在一個答案可以發現這個網站:

 <ListView.ItemContainerStyle> 
     <Style TargetType="{x:Type ListViewItem}"> 
      <Setter Property="Control.Focusable" Value="False"/> 
      <Style.Triggers> 
       <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Background" Value="{x:Null}" /> 
       <Setter Property="BorderBrush" Value="{x:Null}" /> 
       </Trigger> 
      </Style.Triggers> 
     </Style> 
    </ListView.ItemContainerStyle> 

然而,儘管這種變化有助於消除大部分的亮點,它不會刪除仍會出現當單槓鼠標移動到ListView行上。我如何刪除它?

我已經處理了涉及Button的類似問題,並找到了通過刪除其鑲邊來更改Button模板的解決方案。

在這種情況下的ListView/GridView我無法找到相應的鉻和模板進行更改。

回答

14

如果你安裝了Windows SDK,你可以找到所有默認樣式(假設你安裝了樣品)的XAML源:

的%ProgramFiles%\微軟的SDK \的Windows \ V6.1 \ Samples \ WPFSamples.zip

zip文件包含一個文件夾Core,其中包含AeroTheme,LunaTheme等包含默認樣式源的文件夾。不幸的是,這些文件非常大(Aero約8500行),結構或格式不完整(IMO)。

的ListViewItem的默認控件模板看起來是這樣的:

<ControlTemplate TargetType="{x:Type ListViewItem}"> 
    <Border CornerRadius="2" SnapsToDevicePixels="True" 
      BorderThickness="{TemplateBinding BorderThickness}" 
      BorderBrush="{TemplateBinding BorderBrush}" 
      Background="{TemplateBinding Background}"> 
    <Border Name="InnerBorder" CornerRadius="1" BorderThickness="1"> 
     <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition MaxHeight="11" /> 
      <RowDefinition /> 
     </Grid.RowDefinitions> 

     <Rectangle Name="UpperHighlight" Visibility="Collapsed" Fill="#75FFFFFF" /> 
     <GridViewRowPresenter Grid.RowSpan="2" 
           VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
           SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
     </Grid> 
    </Border> 
    </Border> 

    <ControlTemplate.Triggers> 
    <Trigger Property="IsMouseOver" Value="True"> 
     <Setter Property="Background" Value="{StaticResource ListItemHoverFill}" /> 
     <Setter Property="BorderBrush" Value="#FFCCF0FF" /> 
     <Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible" /> 
    </Trigger> 

    <Trigger Property="IsSelected" Value="True"> 
     <Setter Property="Background" Value="{StaticResource ListItemSelectedFill}" /> 
     <Setter Property="BorderBrush" Value="#FF98DDFB" /> 
     <Setter TargetName="InnerBorder" Property="BorderBrush" Value="#80FFFFFF" /> 
     <Setter TargetName="UpperHighlight" Property="Visibility" Value="Visible" /> 
     <Setter TargetName="UpperHighlight" Property="Fill" Value="#40FFFFFF" /> 
    </Trigger> 

    <MultiTrigger> 
     <MultiTrigger.Conditions> 
     <Condition Property="IsSelected" Value="True" /> 
     <Condition Property="Selector.IsSelectionActive" Value="False" /> 
     </MultiTrigger.Conditions> 

     <Setter Property="Background" Value="{StaticResource ListItemSelectedInactiveFill}" /> 
     <Setter Property="BorderBrush" Value="#FFCFCFCF" /> 
    </MultiTrigger> 

    <MultiTrigger> 
     <MultiTrigger.Conditions> 
     <Condition Property="IsSelected" Value="True" /> 
     <Condition Property="IsMouseOver" Value="True" /> 
     </MultiTrigger.Conditions> 

     <Setter Property="Background" Value="{StaticResource ListItemSelectedHoverFill}" /> 
     <Setter Property="BorderBrush" Value="#FF98DDFB" /> 
    </MultiTrigger> 

    <Trigger Property="IsEnabled" Value="False"> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" /> 
    </Trigger> 
    </ControlTemplate.Triggers> 
</ControlTemplate> 

,將全部刪除高亮顯示您最好的選擇可能是用你自己的,只是包括GridViewRowPresenter(也許在一個單一的邊境)取代的ControlTemplate 。不要忘記在禁用控件時加入灰色的觸發器。

+0

上面的亮點必須是它!我在這裏看模板:http://msdn.microsoft.com/en-us/library/ms788717.aspx 因爲它必須是一個不同的主題,我無法解釋吧。 – Tony 2009-08-10 20:07:05

+0

我可以證實UpperHighlight矩形是罪魁禍首。謝謝! – Tony 2009-08-10 20:41:07

+2

令人驚歎......只有在WPF中,我不得不完全重寫樣式以擺脫單個高光元素。 – aqua 2013-05-10 23:40:51

0

使用你的代碼,我根本沒有看到任何線。你現在的默認主題是什麼?月神,航空等?這可能是你的不同於我的,因此在鉻的差異。您的ListView還有其他特殊設置嗎?

Style SnooperShow Me The Template可能會幫助您追蹤負責您所看到的線條的視覺元素。您可能也有興趣re-templating您的ListView得到你想要的效果。

+0

這是Vista的主題,我相信它是航空,因爲我有玻璃效果。確實XP上的人沒有看到高亮欄。 – Tony 2009-08-10 20:04:11

8

我不是在Windows PC的前面,現在來測試這個權利,但我曾與列表框類似的問題,我固定通過將以下爲我Window.Resources

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /> 
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" /> 

不知道是否將盡管你的列表視圖。

+1

幾個博客和awers指向這種方法,但由於某種原因,它從來沒有爲我工作。 – Tony 2009-08-10 20:05:04

+3

謝謝!當我用Style targetType =「ListViewItem」將它放到我的窗口資源中時,這對我有用。我還添加了一行來將SystemColors.HighlightTextBrushKey設置爲SystemColors.WindowTextColor,否則會阻止我的文本顏色切換到背景顏色(從而消失)。 – 2009-10-11 17:35:34

+0

對我來說它適用於沒有Gridview的ListView。但不適用於Gridview。 – Paparazzi 2014-02-03 23:05:57