wpf中的多个样式

问题描述 投票:0回答:1

我想从静态资源定义我的TextBox的设计,如何应用它?

现在我有:

<TextBox  Style="{StaticResource TextBoxHeight }" />

在这里Page.Resources

<Page.Resources>
        <Style x:Key="TextBoxHeight" TargetType="{x:Type TextBox}" >
            <Setter Property="Height" Value="20"/>

        </Style>
        <Style x:Key="TextBoxBorder" TargetType="{x:Type Border}"  >
            <Setter Property="CornerRadius" Value="10"/>
        </Style>
 </Page.Resources>

但我需要:

<TextBox   Style="{StaticResource TextBoxHeight }" Style="{StaticResource TextBoxBorder }" />

但它给出了错误“属性'样式'设置了多次”

wpf xaml
1个回答
1
投票

您不能多次设置Style属性。并且你不能将StyleTargetTypeBorder应用于TextBox。但是在Border风格的Resources字典中加入一个隐含的Button风格应该有效:

<Style x:Key="TextBoxHeight1" TargetType="{x:Type TextBox}" >
    <Setter Property="Height" Value="20"/>
    <Style.Resources>
        <Style TargetType="{x:Type Border}">
            <Setter Property="CornerRadius" Value="10"/>
        </Style>
    </Style.Resources>
</Style>
© www.soinside.com 2019 - 2024. All rights reserved.