Reputation: 46
I am having difficulties getting my grid column to be full width. As you can see, I tried HorizontalAlignment="Stretch" (also tried Center) on the textblock and Width="*" (also tried Auto) but neither seem to work.
I want the column to be the full window width and the 'welcome' text to be centered.
<Grid>
<DockPanel LastChildFill="False">
<TextBlock DockPanel.Dock="Top" Text="Drink & Drive"/>
<TextBlock DockPanel.Dock="Bottom" Text="Drink & Drive - 2020"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" HorizontalAlignment="Stretch" Text="WELCOME"/>
</Grid>
</DockPanel>
</Grid>
Result:
Thanks.
Upvotes: 0
Views: 485
Reputation: 35720
I suggest to use 1 Grid, instead of Grid + DockPanel + Grid
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Drink & Drive"/>
<TextBlock Grid.Row="1" Text="WELCOME" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<TextBlock Grid.Row="2" Text="Drink & Drive - 2020"/>
</Grid>
Upvotes: 1