views:

248

answers:

1

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’.

+3  A: 

Add this line to your style:

<Setter Property="TextAlignment" Value="Center"/>
Charlie
Thanks, I thought HorizontalContentAlignment was the property I needed.
Number8