首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重置被覆盖的SystemColors

重置被覆盖的SystemColors
EN

Stack Overflow用户
提问于 2014-01-27 21:16:43
回答 1查看 92关注 0票数 1

我在我的ListView中更改了SystemColors.HighlightBrushKeySystemColors.ControlBrushKey,它工作得很好;但是这个列表视图在它的每个ListViewItem中都包含了其他复杂的控件(例如,other ListView,DataGrid),并且这个新的系统颜色应用于所有子控件。

代码语言:javascript
复制
<!--  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就能正常工作。

有没有其他方法来解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2014-01-27 21:31:13

您应该使用覆盖ListViewItem的默认模板,而不是覆盖SystemColors。

覆盖模板并移除selection和mouseOver的触发器,如下所示:

代码语言:javascript
复制
    <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下,并在需要的任何地方使用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21381932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档