Reset inherited WPF style?

余生长醉 提交于 2019-11-30 04:56:45

问题


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).

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?

I've tried using

<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.


回答1:


There are 2 ways to reset the style:

  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>
    
  2. 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>
    


来源:https://stackoverflow.com/questions/30502451/reset-inherited-wpf-style

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!