How to fill empty space on the Grid with Textblock?

Asked

Viewed 61 times

3

I have the following XAML

<Window x:Class="ambiente_teste.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ambiente_teste"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <StackPanel Width="120" Margin="5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="120"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0" Background="#FF38C59F"></StackPanel>
                <TextBlock Grid.Row="1" Text="title" Foreground="LightGray"  VerticalAlignment="Top" TextAlignment="Center"/>
  <!--preencher espaços--> <TextBlock Grid.Row="2" Text="text" Foreground="LightGray" VerticalAlignment="Top" TextAlignment="Center" />
            </Grid>
        </StackPanel>
    </Grid>
</Window>

As you can see, I have spaces left in the third line of Grid. How can I fill these spaces with the TextBlock?

I want to do similar to Dock.Fill, of WindowsForms.

  • It’s like putting an image of how you’d like it to look?

1 answer

0


The VerticalAlignment has to be in Stretch. Only thus the TextBlock will fill in the blanks.

<Window x:Class="ambiente_teste.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ambiente_teste"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <StackPanel Width="120" Margin="5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="120"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="30"/>
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0" Background="#FF38C59F"></StackPanel>
                <TextBlock Grid.Row="1" Text="title" Foreground="LightGray"  VerticalAlignment="Stretch" TextAlignment="Center"/>
                <!--preencher espaços-->
                <TextBlock Grid.Row="2" Text="text" Foreground="LightGray" VerticalAlignment="Stretch" TextAlignment="Center"/>
            </Grid>
        </StackPanel>
    </Grid>
</Window>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.