2009-07-31 76 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