Reputation: 91
I want to define the design of my TextBox
from static resource, how to apply that?
For now I have:
<TextBox Style="{StaticResource TextBoxHeight }" />
And here 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>
But I need that:
<TextBox Style="{StaticResource TextBoxHeight }" Style="{StaticResource TextBoxBorder }" />
But it gives error "The property 'Style' is set multiple times"
Upvotes: 0
Views: 1150
Reputation: 169200
You can't set the Style
property more than once. And you can't apply a Style
with a TargetType
of Border
to a TextBox
. But putting an implicit Border
style in the Resources
dictionary of the Button
style should work:
<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>
Upvotes: 1