重置继承的WPF样式? [英] Reset inherited WPF style?

查看:177
本文介绍了重置继承的WPF样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的App.xaml部分中,我有一个ResourceDictionary元素,该元素定位诸如DataGridColumnHeaderDataGridCell之类的东西,并对它们应用自定义样式.这些定义是全局的(因为它们不使用x:key-它们适用于该类型的所有实例).

In the App.xaml portion of my application I have a ResourceDictionary element that targets things like DataGridColumnHeader and DataGridCell and applies custom styling to them. These definitions are global (in that they don't use a x:key - they apply to all instances of the type).

是否可以将这些类型的样式完全重置为基本" Aero主题(或当前正在使用的任何主题),以便在我的应用程序的小节中使用?

Is it possible to completely reset the style of these types to the 'base' Aero theme (or whatever theme is currently in use) for use in a subsection of my application?

我尝试使用

<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
    </Style>

似乎什么也没做,因为我猜它只是继承自己的.

Which doesn't seem to do anything, as I'm guessing its just inheriting itself.

推荐答案

有两种方法可以重置样式:

There are 2 ways to reset the style:

  1. 将元素的样式属性设置为{x:Null}.您将必须在每个元素上执行此操作.

  1. Set the style property of the element to {x:Null}. You will have to do this on every element.

<Button Height="50" Style="{x:Null}"></Button>

  • 在包含要重置元素的元素资源中定义一个空样式.不要指定BasedOn,否则它将继承所有属性,并且不会将它们重置为标准属性(如您正确注意到的那样).

  • Define an empty style in the resources of the element containing the elements you want to reset. Don't specify BasedOn, otherwise it will inherit all properties and does not reset them to standard (as you correctly noticed).

    <Style TargetType="{x:Type DataGridColumnHeader}">
    </Style>
    

  • 这篇关于重置继承的WPF样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆