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