Home > Software design >  Combobox Full Width in WPF DataGridCell
Combobox Full Width in WPF DataGridCell

Time:07-07

I have a combobox item in the datagrid as below.

<DataGrid.Columns>
...
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox ItemsSource="{Binding Source={StaticResource LookUps}}" HorizontalAlignment="Center" DisplayMemberPath="LookUpName" SelectedValuePath="Id" SelectedValue="{Binding QLookupId, Mode=TwoWay}" IsEnabled="True" SelectionChanged="cbLookUp_SelectionChanged" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
...
</DataGrid.Columns>

How can I set the width of this combobox to cover the width of the datagridcell?

CodePudding user response:

Remove HorizontalAlignment="Center".

Then the ComboBox will stretch to fit the width of the cell by default.

  • Related