0
votes

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 &amp; Drive"/>
            <TextBlock DockPanel.Dock="Bottom" Text="Drink &amp; 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:

screenshot

Thanks.

1
can you give any feedback to my answer?ASh

1 Answers

1
votes

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 &amp; Drive"/>        

    <TextBlock Grid.Row="1" Text="WELCOME" HorizontalAlignment="Center" VerticalAlignment="Center"/>

    <TextBlock Grid.Row="2" Text="Drink &amp; Drive - 2020"/>
</Grid>