我在我的ListView中更改了SystemColors.HighlightBrushKey和SystemColors.ControlBrushKey,它工作得很好;但是这个列表视图在它的每个ListViewItem中都包含了其他复杂的控件(例如,other ListView,DataGrid),并且这个新的系统颜色应用于所有子控件。
<!-- This resource is added to remove the blue highlighting
in the selected ListView item. -->
<SolidColorBrush
x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent" />
<!-- This resource is added to remove the background highlighting
of the inactive selected ListView item. -->
<SolidColorBrush
x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="Transparent" />对于这个ListView的子控件,有没有办法将这个系统颜色重置为原始颜色?
我面临的实际问题是,这些被覆盖的系统颜色被应用到(ListView的)子控件的上下文菜单中;这工作得很好,但当使用Windows Classic主题时,ContextMenus使用这些系统颜色,看起来很奇怪。因此,我希望如果我能将SystemColors重置为原始版本,那么ContextMenu就能正常工作。
有没有其他方法来解决这个问题?
发布于 2014-01-27 21:31:13
您应该使用覆盖ListViewItem的默认模板,而不是覆盖SystemColors。
覆盖模板并移除selection和mouseOver的触发器,如下所示:
<ListView>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
Name="Bd"
SnapsToDevicePixels="True">
<ContentPresenter Content="{TemplateBinding ContentControl.Content}"
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="Bd">
<Setter.Value>
<DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>如果想要在多个ListView上应用,请将此资源放在App.Resources下,并在需要的任何地方使用。
https://stackoverflow.com/questions/21381932
复制相似问题