Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

question from:https://stackoverflow.com/questions/11581475/inherit-style-from-default-style

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
455 views
Welcome To Ask or Share your Answers For Others

1 Answer

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...