R – Overriding styles defined in generic.xaml

generic.xamlwpfxaml

I have a custom controls library, in which I defined a control template, that uses some custom styles. My control template is located in the Generic.xaml file, and the styles it uses are also located there, and accessed by the control template with the StaticResource markup extension.
In some cases, when I use this controls library, I want to change some of the styles used template, but I don't know how to do that.
I thought that if I would add to my Window's resource dictionary a style with a name, that is used by the template, my style will "override" the one that is defined in Generic.xaml file, but it didn't work.
What should I do?

Best Answer

does that work?

<Style TargetType="{x:Type YourCustomControl}" 
       BasedOn="{StaticResource {x:Type YourCustomControl}}">
    <Setter Property="SomeStylePropertyOfYourCustomControl" 
            Value="{StaticResource SomeStyleYouWantToUseInstead}"/>
</Style>
Related Topic