2009-08-09 158 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