nikotromus
nikotromus

Reputation: 1054

How to horizontally align textblocks within a stackpanel

I have a group of textblocks that are located within a stackpanel. There is no options to horizontally align the content of the textblocks. How do I horizontally align these columns to 'center' without hacking the margins?

enter image description here

Here is the 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>

Upvotes: 0

Views: 70

Answers (1)

Muhammad Azeez
Muhammad Azeez

Reputation: 926

Have you tried TextAlignment?

Something like:

<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>

Upvotes: 2

Related Questions