从默认样式继承样式 [英] inherit style from default style

查看:24
本文介绍了从默认样式继承样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,文本框有一个自定义样式.定义为:

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.

我需要创建另一种基于默认样式的样式.但是如何在 BasedOn 属性中指定我的新样式应该使用默认样式?

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?

推荐答案

使用你想要扩展的控件类型

Use the type of the control you would like to extend

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

完整示例:

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

这篇关于从默认样式继承样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆