如何水平对齐堆栈面板中的文本块
How to horizontally align textblocks within a stackpanel
我有一组位于堆栈面板中的文本块。没有水平对齐文本块内容的选项。如何在不改变边距的情况下将这些列水平对齐 'center'?
这是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>
你试过了吗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>
我有一组位于堆栈面板中的文本块。没有水平对齐文本块内容的选项。如何在不改变边距的情况下将这些列水平对齐 'center'?
这是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>
你试过了吗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>