Reputation: 12910
I define a style in app.xaml:
<Style x:Key="textBoxCenter" TargetType="{x:Type TextBox}">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
I use the style in window1.xaml:
<TextBox
Style="{StaticResource textBoxCenter}"
Background="BlanchedAlmond" Text="BobbleHead" />
<TextBox
Style="{StaticResource textBoxCenter}"
Background="AliceBlue" Text="WhammyBar" />
However, the horizontal alignment, both in the Designer and at runtime, is ‘Left’, even though the Properties toolbar says it is ‘Center’.
Upvotes: 2
Views: 774
Reputation: 15247
Add this line to your style:
<Setter Property="TextAlignment" Value="Center"/>
Upvotes: 3