3

Eu tenho o seguinte 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>

Como podem perceber, eu tenho espaços sobrando na terceira linha do Grid. Como eu posso preencher esses espaços com o TextBlock?

Eu quero fazer semelhante ao Dock.Fill, do WindowsForms.

1
  • Tem como por uma imagem de como vc gostaria que ficasse? Commented 16/10/2020 às 21:47

1 Resposta 1

0

O VerticalAlignment tem que estar em Stretch. Só assim o TextBlock vai preencher os espaços vazios.

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

Você deve fazer log-in para responder a esta pergunta.