WPF 文本框最大宽度
WPF textbox max width
我希望 MyTextBox 占用整个宽度。标签的大小将根据所选语言而变化,并展开第一列。网格的第二列包括 MyTextBox 并且应该相应地扩展以占用整个宽度。
我尝试了 HorizontalAlignment="Stretch,但似乎大小是根据第二列(堆栈面板)的第一行定义的。
有什么想法吗?
<TabControl Grid.Row="1" Margin="0 4 0 0" >
<TabItem Style="{DynamicResource MenuLevel2}" Header="Online Meeting">
<Grid HorizontalAlignment="Stretch" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label VerticalAlignment="Center" Grid.Row="0" Grid.Column="0">Default Passcode</Label>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="10 0 0 0" HorizontalAlignment="Stretch" Width="Auto" >
<TextBox MaxLength="100" horizontalAlignment="Stretch" Margin="0 0 10 0"/>
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Stretch" Click="chkBox_OMRandomPIN_Click"/>
<Label Content="Random" Margin="0 1 0 0" Width="56" HorizontalAlignment="Stretch" />
</StackPanel>
<Label Grid.Row="1" Grid.Column="0" Content="Default location label" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" MaxLength="100" Name="MyTextBox" Margin="11,3,0,3" Height="25" HorizontalAlignment="Stretch" />
</Grid>
</TabItem>
你那里的自动宽度太多了。
特别是堆栈面板所在的列。
这对我有用:
<TabControl Grid.Row="1" Margin="0 4 0 0" >
<TabItem Header="Online Meeting">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label VerticalAlignment="Center" Grid.Row="0" Grid.Column="0">Default Passcode</Label>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="10 0 0 0" HorizontalAlignment="Stretch">
<TextBox MaxLength="100" HorizontalAlignment="Stretch" Margin="0 0 10 0"/>
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Stretch" Click="chkBox_OMRandomPIN_Click"/>
<Label Content="Random" Margin="0 1 0 0" Width="56" HorizontalAlignment="Stretch" />
</StackPanel>
<Label Grid.Row="1" Grid.Column="0" Content="Default location label" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" MaxLength="100" Name="MyTextBox" Margin="11,3,0,3" Height="25" />
</Grid>
</TabItem>
特别注意事项
我从堆栈面板的宽度中删除了 Auto 并制作了第二列 * 而不是 auto
我希望 MyTextBox 占用整个宽度。标签的大小将根据所选语言而变化,并展开第一列。网格的第二列包括 MyTextBox 并且应该相应地扩展以占用整个宽度。 我尝试了 HorizontalAlignment="Stretch,但似乎大小是根据第二列(堆栈面板)的第一行定义的。 有什么想法吗?
<TabControl Grid.Row="1" Margin="0 4 0 0" >
<TabItem Style="{DynamicResource MenuLevel2}" Header="Online Meeting">
<Grid HorizontalAlignment="Stretch" Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label VerticalAlignment="Center" Grid.Row="0" Grid.Column="0">Default Passcode</Label>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="10 0 0 0" HorizontalAlignment="Stretch" Width="Auto" >
<TextBox MaxLength="100" horizontalAlignment="Stretch" Margin="0 0 10 0"/>
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Stretch" Click="chkBox_OMRandomPIN_Click"/>
<Label Content="Random" Margin="0 1 0 0" Width="56" HorizontalAlignment="Stretch" />
</StackPanel>
<Label Grid.Row="1" Grid.Column="0" Content="Default location label" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" MaxLength="100" Name="MyTextBox" Margin="11,3,0,3" Height="25" HorizontalAlignment="Stretch" />
</Grid>
</TabItem>
你那里的自动宽度太多了。
特别是堆栈面板所在的列。
这对我有用:
<TabControl Grid.Row="1" Margin="0 4 0 0" >
<TabItem Header="Online Meeting">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="32" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label VerticalAlignment="Center" Grid.Row="0" Grid.Column="0">Default Passcode</Label>
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="10 0 0 0" HorizontalAlignment="Stretch">
<TextBox MaxLength="100" HorizontalAlignment="Stretch" Margin="0 0 10 0"/>
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Stretch" Click="chkBox_OMRandomPIN_Click"/>
<Label Content="Random" Margin="0 1 0 0" Width="56" HorizontalAlignment="Stretch" />
</StackPanel>
<Label Grid.Row="1" Grid.Column="0" Content="Default location label" VerticalAlignment="Center" />
<TextBox Grid.Row="1" Grid.Column="1" MaxLength="100" Name="MyTextBox" Margin="11,3,0,3" Height="25" />
</Grid>
</TabItem>
特别注意事项
我从堆栈面板的宽度中删除了 Auto 并制作了第二列 * 而不是 auto