我想从静态资源定义我的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 }" />
但它给出了错误“属性'样式'设置了多次”
您不能多次设置Style
属性。并且你不能将Style
与TargetType
的Border
应用于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>