inherit style from default style

Bogdan Verbenets picture Bogdan Verbenets · Jul 20, 2012 · Viewed 19.4k times · Source

In my project there is a custom style for text box. It is defined as:

<Style TargetType="TextBox"/>

So it is applied to all text box child controls by default.

I need to create another style that is based on default style. But how do I specify in the BasedOn attribute that my new style should use the default style?

Answer

Aphelion picture Aphelion · Jul 20, 2012

Use the type of the control you would like to extend

BasedOn="{StaticResource {x:Type TextBox}}"

Full example:

<Style x:Key="NamedStyle" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
    <Setter property="Opacity" value="0.5" />
</Style>