gpt4 book ai didi

WPF 文本框拉伸(stretch)

转载 作者:行者123 更新时间:2023-12-04 10:30:43 25 4
gpt4 key购买 nike

我在下面有 XAML,它显示了我想要做什么。这很简单。

我有一个包含网格的窗口。网格包含一个带有多个选项卡项的选项卡控件。下面代码中显示的选项卡项包含一个网格。网格有两列和六行。每行包含一个标签(第 0 列)和文本框(第 1 列)。我希望标签列消耗所需的空间。我希望文本框列消耗行的其余宽度。而且,当用户水平调整窗口大小时,我希望文本框列随着窗口收缩和扩展。下面的代码不这样做,我不确定我需要做什么来解决这个问题。

<Grid Background="#18AFA117">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Content="Generate" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="54,8,0,0" Name="Generatebutton" VerticalAlignment="Top" Width="75" Click="Generatebutton_Click" />
<Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="151,8,0,0" Name="CancelButton" VerticalAlignment="Top" Width="75" Grid.Row="1" Click="CancelButton_Click" />
<TabControl HorizontalAlignment="Stretch" Margin="5,5,5,416" Name="tabControl1" VerticalAlignment="Stretch" Height="Auto" SelectionChanged="tabControl1_SelectionChanged">
<TabItem Header="TFS Configuration" Name="TFSTab">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Content="TFS Server:" Grid.Column="0" Grid.Row="0" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label04" VerticalAlignment="Top" />
<Label Content="TFS Workspace Name:" Grid.Column="0" Grid.Row="1" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label05" VerticalAlignment="Top" />
<Label Content="TFS Local Folder:" Grid.Column="0" Grid.Row="2" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label06" VerticalAlignment="Top" />
<Label Content="TFS Framework Solution Path:" Grid.Column="0" Grid.Row="3" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label07" VerticalAlignment="Top" />
<Label Content="TFS Checkin Comments:" Grid.Column="0" Grid.Row="4" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label08" VerticalAlignment="Top" />
<Label Content="TFS Shelveset Name:" Grid.Column="0" Grid.Row="5" Height="25" HorizontalAlignment="Left" Margin="6,1,0,0" Name="label09" VerticalAlignment="Top" />

<TextBox Grid.Row="0" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSServer" VerticalAlignment="Top"/>
<TextBox Grid.Row="1" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSWorkspaceName" VerticalAlignment="Top" />
<TextBox Grid.Row="2" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSLocalFolder" VerticalAlignment="Top" />
<ComboBox Grid.Row="3" Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSSolutionPaths" VerticalAlignment="Top" />
<TextBox Grid.Row="4" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSCheckinComments" VerticalAlignment="Top" />
<TextBox Grid.Row="5" Grid.Column="1" Height="21" HorizontalAlignment="Stretch" Margin="13,3,0,0" Name="TFSShelvesetName" VerticalAlignment="Top" />
</Grid>
</TabItem>

最佳答案

将包含文本框的列的宽度设置为“星号”:*
无需将文本框的 Horizo​​ntalAlignment 设置为 Stretch;网格负责处理。

关于WPF 文本框拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4828747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com