Ton*_*ony 8 wpf listview highlight wpf-controls
我有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>
Run Code Online (Sandbox Code Playgroud)
但是,虽然此更改有助于删除大部分突出显示,但它不会删除鼠标在ListView行上移动时仍出现的水平条.我该如何删除它?
我已经处理了涉及Button的类似问题,并找到了一个解决方案,通过删除其chrome来更改Button模板.
在ListView/GridView的这种情况下,我无法找到要更改的相应chrome和模板.
Phi*_*ney 14
如果安装了Windows SDK,则可以在以下位置找到所有默认样式的XAML源(假设您已安装样本):
%ProgramFiles%\ Microsoft SDKs\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>
Run Code Online (Sandbox Code Playgroud)
删除所有突出显示的最佳选择可能是将您自己的ControlTemplate替换为仅包含GridViewRowPresenter(可能在单个边框中).不要忘记包含禁用控件时灰色项目的触发器.
我现在不在Windows PC前面对此进行测试,但我遇到了类似的问题,我通过将以下内容放入我的Window.Resources来解决这个问题.
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
Run Code Online (Sandbox Code Playgroud)
不确定它是否适用于您的列表视图.