Подтвердить что ты не робот

Как расширить текстовые поля, чтобы заполнить оставшееся пространство сетки?

У меня есть следующее окно с некоторым входом textboxes. Но эти текстовые поля не будут расширяться, чтобы заполнить оставшееся пространство второго столбца. Кроме того, когда размер окна изменяется, textboxes не соответствует размеру,

Вот мое окно

enter image description here

Вот моя разметка XAML

<Window x:Class="WpfApplication8.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Grid ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"></ColumnDefinition>
            <ColumnDefinition Width="*"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="28"></RowDefinition>
        </Grid.RowDefinitions>

        <Label Content="First Name" Grid.Column="0" Grid.Row="0"></Label>
        <Label Content="Last Name" Grid.Column="0" Grid.Row="1"></Label>
        <Label Content="Street Name" Grid.Column="0" Grid.Row="2"></Label>
        <Label Content="Suburb" Grid.Column="0" Grid.Row="3"></Label>
        <Label Content="City" Grid.Column="0" Grid.Row="4"></Label>

        <TextBox Width="313" Grid.Column="1" Margin="3" HorizontalAlignment="Left"/>
        <TextBox Width="313" Grid.Column="1" Grid.Row="1" Margin="3" 
                 HorizontalAlignment="Left" ></TextBox>
        <TextBox Width="313" Grid.Column="1" Grid.Row="2" Margin="3" 
                 HorizontalAlignment="Left"></TextBox>
        <TextBox Width="313" Grid.Column="1" Grid.Row="3" Margin="3" 
                 HorizontalAlignment="Left"></TextBox>
        <TextBox Width="313" Grid.Column="1" Grid.Row="4" Margin="3"
                 HorizontalAlignment="Left"></TextBox>

        <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="5" 
                    HorizontalAlignment="Right">
        <Button Content="Save" Grid.Column="1" Grid.Row="5" Width="100" Margin="3" />
        <Button Content="Exit" Grid.Column="1" Grid.Row="5" Width="100" 
                 HorizontalAlignment="Right" Margin="3"></Button>
        </StackPanel>
        <!--<TextBox Width="313" Grid.Column="1"></TextBox>-->
    </Grid>
</Window>
  • Можно ли расширить textboxes, чтобы заполнить оставшееся пространство во втором столбце?
  • Есть ли возможность изменить размер textboxes при изменении размера формы?
4b9b3361

Ответ 1

У вас есть Width hardcoded, поэтому он всегда будет оставаться прежним. Удалите его и измените выравнивание, чтобы растянуть

<TextBox Grid.Column="1" Margin="3" HorizontalAlignment="Stretch">

Ответ 2

просто поместите HorizontalAlignment = "Stretch" и удалите Width