2009-07-31 50 views
2

我在App.xaml中定义一个样式:奇怪Horizo​​ntalContentAlignment(非)行为

<Style x:Key="textBoxCenter" TargetType="{x:Type TextBox}"> 
    <Setter Property="VerticalContentAlignment" Value="Center"/> 
    <Setter Property="HorizontalContentAlignment" Value="Center"/> 
</Style> 

我使用样式中window1.xaml:

<TextBox 
    Style="{StaticResource textBoxCenter}" 
    Background="BlanchedAlmond" Text="BobbleHead" /> 
<TextBox 
    Style="{StaticResource textBoxCenter}" 
    Background="AliceBlue" Text="WhammyBar" /> 

然而,水平对齐,无论是在设计器和在运行时,是'左',即使属性工具栏说它是'中心'。

回答

3

此行添加到您的风格:

<Setter Property="TextAlignment" Value="Center"/> 
+0

谢谢你,我还以为Horizo​​ntalContentAlignment是我所需要的属性。 – Number8 2009-07-31 15:50:31

相关问题