Reset inherited WPF style?

In the App.xaml part of my application, I have an element ResourceDictionary

that targets things like DataGridColumnHeader

and DataGridCell

, and applies a special style to them. These definitions are global (because they don't use the x key: they apply to all instances of the type).

Can I fully style these types for a "base" Aero theme (or any other theme currently) for use in a subsection of my application?

I have tried using

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

      

Which doesn't seem to do anything, as I am assuming it is just inheriting from itself.

+3


source to share


1 answer


There are two ways to reset a style:



  • Set the style property of the element {x:Null}

    . You will need 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 won't reset them to the default (as you rightly pointed out).

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

+5


source







All Articles