我希望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>
答案 0 :(得分:2)
其中的自动宽度过多。
尤其是stackpanel进入的列。
这对我有用:
<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>
特别注意的事情。
我删除了自动调整堆栈面板的宽度,并将第二列改为*而不是自动