当我最大化/最小化它时,如何调整TextBoxe' s / s以适应窗口大小?此时文本框只是转到窗口的中心。我希望他们调整大小以适应网格列和行大小。我怎样才能做到这一点?我尝试了解列和行文本框所属的内容,但是,它会相应地调整为ColumnDefinition,但这并没有改变任何内容。
<DockPanel Margin="2,46,0,0" Name="dockPanel1" Width="Auto">
<TabControl Height="Auto" Name="tabControl1" Width="Auto" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" DockPanel.Dock="Top">
<TabItem Header="tabItem1" Name="tabItem1">
<Grid Name="grid1" HorizontalAlignment="Center" VerticalAlignment="Top" Height="523" Width="766">
<Grid.RowDefinitions>
<RowDefinition MinHeight="0" Height="43*" />
<RowDefinition Height="45*" />
<RowDefinition Height="435*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition MinWidth="0" Width="Auto" />
<ColumnDefinition Width="Auto" MinWidth="100" />
<ColumnDefinition Width="385*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Grid.Row="0" Height="27" Name="textBox1" VerticalAlignment="Top" Margin="0,4,0,0" HorizontalAlignment="Right" Width="141" FontSize="14" HorizontalContentAlignment="Stretch" />
<Label Content="Label" Height="9" HorizontalAlignment="Left" Margin="16,7,0,0" Name="label1" VerticalAlignment="Top" Width="35" />
<Label Content="Supplier" Height="27" Name="label2" VerticalAlignment="Top" FontSize="14" FontFamily="Tahoma" FontWeight="Bold" Margin="6,4,0,0" Width="133" IsEnabled="True" HorizontalAlignment="Left" Foreground="Black" Background="White" />
<TextBox FontSize="14" Height="27" HorizontalAlignment="Stretch" Margin="140,6,0,0" Name="textBox11" VerticalAlignment="Top" Width="141" Grid.Row="1" />
<Label Content="Supplier Bank" FontFamily="Tahoma" FontSize="14" FontWeight="Bold" Height="27" Margin="6,6,142,0" Name="label3" VerticalAlignment="Top" Width="133" Grid.Row="1" Background="White" />
<TextBox FontSize="14" Height="27" HorizontalAlignment="Stretch" Margin="140,7,0,0" Name="textBox12" VerticalAlignment="Top" Width="141" Grid.Row="2" />
<Label Content="Account Number" FontFamily="Tahoma" FontSize="14" FontWeight="Bold" Height="27" Margin="6,7,142,0" Name="label4" VerticalAlignment="Top" Width="133" Grid.Row="2" Background="White" />
<TextBox FontSize="14" Height="27" Margin="134,4,110,0" Name="textBox2" VerticalAlignment="Top" Grid.Column="2" HorizontalAlignment="Stretch" Width="141" DataContext="{Binding ElementName=grid1, Path=ActualWidth}" />
<Label Content="Buyer" FontFamily="Tahoma" FontSize="14" FontWeight="Bold" Height="27" Margin="0,4,252,0" Name="label5" VerticalAlignment="Top" Width="133" Grid.Column="2" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Background="White" />
<TextBox FontSize="14" Grid.Row="1" Height="27" HorizontalAlignment="Left" Margin="134,6,0,0" Name="textBox3" VerticalAlignment="Top" Width="141" Grid.Column="2" />
<Label Content="Buyer Bank" FontFamily="Tahoma" FontSize="14" FontWeight="Bold" Grid.Row="1" Height="27" Margin="0,6,0,0" Name="label6" VerticalAlignment="Top" Width="133" Grid.Column="2" HorizontalAlignment="Left" Background="White" />
<TextBox FontSize="14" Grid.Row="2" Height="27" HorizontalAlignment="Left" Margin="134,7,0,0" Name="textBox4" VerticalAlignment="Top" Width="141" Grid.Column="2" />
<Label Content="Account Number" FontFamily="Tahoma" FontSize="14" FontWeight="Bold" Grid.Row="2" Height="27" Margin="0,7,0,0" Name="label7" VerticalAlignment="Top" Width="133" Grid.Column="2" HorizontalAlignment="Left" Background="White" />
</Grid>
</TabItem>
<TabControl.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0.035" />
<GradientStop Color="#FF1B327A" Offset="0.528" />
<GradientStop Color="#FF001E98" Offset="0.278" />
</LinearGradientBrush>
</TabControl.Background>
</TabControl>
</DockPanel>
答案 0 :(得分:3)
不要为width属性使用静态值。
您可以尝试“HorizontalAlignment = Stretch”。