加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 样式完全改变

发布时间:2020-12-16 00:25:16 所属栏目:百科 来源:网络整理
导读:怎么来这个ModernUI TextBox 改变它的外观 当我所做的只是添加这种风格: UserControl.Resources Style TargetType="{x:Type TextBox}" Setter Property="TextAlignment" Value="Right"/ /Style/UserControl.Resources 当我直接在元素中设置属性时: TextBox
怎么来这个ModernUI TextBox

改变它的外观

当我所做的只是添加这种风格:

<UserControl.Resources>
    <Style TargetType="{x:Type TextBox}">
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>
</UserControl.Resources>

当我直接在元素中设置属性时:

<TextBox Text="" TextAlignment="Right"></TextBox>

一切看起来都应该如此:

我真的不明白,并会感谢短暂的暗示.

解决方法

问题在于它将完全取代其他风格.

添加BasedOn属性以指定此样式将扩展ModernUI样式:

<UserControl.Resources>
    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource whateverModernUIStyleNameIs}">
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>
</UserControl.Resources>

您还可以指定implict样式:BasedOn =“{StaticResource {x:Type TextBox}}”,如Mike C.所指出的那样.

阅读此问题以获取更多详细信息:How to apply multiple styles in WPF

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读