inherit style from default style

南楼画角 提交于 2019-11-26 08:27:12

问题


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?


回答1:


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>


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!