问题
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:
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>
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