xamluwpuwp-xamldatagridcell

ComboBox in a Grid does not fill a grid's cell width


I have a ComboBox in a Grid along with several text boxes.
The Grid is defined like this:

<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>

Note that I have added in HorizontalContentAlignment. This has no effect in making the combo fill the Grid, and it still looks like this:

enter image description here

How can I make the ComboBox fill the width of the Cell, equally with the other TextBoxes?


Solution

  • 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 as Stretch.

    <ComboBox Grid.Column="9" 
    Text="{x:Bind ViewModel.ComboText}" 
    ItemsSource="{x:Bind ViewModel.ComboItems}" 
    HorizontalAlignment="Stretch" />