网格中的组合框不填充网格的单元格宽度
ComboBox in a Grid does not fill a grid's cell width
我在 Grid
中有一个 ComboBox
以及几个文本框。
Grid
定义如下:
<Grid Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" ColumnSpacing="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- All of the text boxes -->
<TextBlock Grid.Column="8" Text="Combo" VerticalAlignment="Center" />
<ComboBox Grid.Column="9" Text="{x:Bind ViewModel.ComboText}" ItemsSource="{x:Bind ViewModel.ComboItems}" HorizontalContentAlignment="Stretch" />
</Grid>
请注意,我已在 HorizontalContentAlignment
中添加。这对使组合填充 Grid
没有影响,它仍然看起来像这样:
如何让 ComboBox
填充 Cell
的宽度,与其他 TextBox
一样?
ComboBox in a Grid does not fill a grid's cell width
HorizontalContentAlignment
is used to make horizontal alignment of the control's content. If you want to make ComboBox fill a gird cell please set HorizontalAlignment
作为 Stretch
.
<ComboBox Grid.Column="9"
Text="{x:Bind ViewModel.ComboText}"
ItemsSource="{x:Bind ViewModel.ComboItems}"
HorizontalAlignment="Stretch" />
我在 Grid
中有一个 ComboBox
以及几个文本框。
Grid
定义如下:
<Grid Grid.Row="1" Grid.Column="1" Margin="0,10,0,0" ColumnSpacing="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- All of the text boxes -->
<TextBlock Grid.Column="8" Text="Combo" VerticalAlignment="Center" />
<ComboBox Grid.Column="9" Text="{x:Bind ViewModel.ComboText}" ItemsSource="{x:Bind ViewModel.ComboItems}" HorizontalContentAlignment="Stretch" />
</Grid>
请注意,我已在 HorizontalContentAlignment
中添加。这对使组合填充 Grid
没有影响,它仍然看起来像这样:
如何让 ComboBox
填充 Cell
的宽度,与其他 TextBox
一样?
ComboBox in a Grid does not fill a grid's cell width
HorizontalContentAlignment
is used to make horizontal alignment of the control's content. If you want to make ComboBox fill a gird cell please set HorizontalAlignment
作为 Stretch
.
<ComboBox Grid.Column="9"
Text="{x:Bind ViewModel.ComboText}"
ItemsSource="{x:Bind ViewModel.ComboItems}"
HorizontalAlignment="Stretch" />