风格完全改变

pet*_*ter 3 c# wpf xaml

怎么来这个ModernUI TextBox

在此输入图像描述

改变它的外观

在此输入图像描述

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

<UserControl.Resources>
    <Style TargetType="{x:Type TextBox}">
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

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

<TextBox Text="" TextAlignment="Right"></TextBox>
Run Code Online (Sandbox Code Playgroud)

一切看起来都应该如此:

在此输入图像描述

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

Dav*_*ret 6

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

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

<UserControl.Resources>
    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource whateverModernUIStyleNameIs}">
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)

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

阅读此问题以获取更多详细信息:如何在WPF中应用多个样式