如何在堆栈面板中水平对齐文本块

时间:2018-11-12 16:08:09

标签: wpf xaml textblock

我在堆栈面板中有一组文本块。没有用于水平对齐文本块内容的选项。如何在不破坏边距的情况下将这些列水平对齐到“居中”?

enter image description here

这是xaml:

<StackPanel Orientation="Horizontal" Background="{Binding RowColor}" >
    <TextBlock Text="{Binding PlayerNumber}" Padding="5" Width="50" />
    <TextBlock Text="{Binding PlayerName}"  Padding="5"  Width="200" />
    <TextBlock Text="{Binding Points}"  Padding="5"  Width="50"/>
    <TextBlock Text="{Binding Fouls}"  Padding="5" Width="50" />
    <TextBlock Text="{Binding Rebounds}"  Padding="5"  Width="50" />
</StackPanel>

1 个答案:

答案 0 :(得分:2)

您尝试过TextAlignment吗?

类似的东西:

<StackPanel Orientation="Horizontal" Background="{Binding RowColor}" >
   <TextBlock Text="{Binding PlayerNumber}" Padding="5" Width="50" TextAlignment="Center" />
   <TextBlock Text="{Binding PlayerName}"  Padding="5"  Width="200" TextAlignment="Center" />
   <TextBlock Text="{Binding Points}"  Padding="5"  Width="50" TextAlignment="Center"/>
   <TextBlock Text="{Binding Fouls}"  Padding="5" Width="50" TextAlignment="Center" />
   <TextBlock Text="{Binding Rebounds}"  Padding="5"  Width="50" TextAlignment="Center" />
</StackPanel>