Make WPF ComboBoxes fill a whole column width

前端 未结 1 1164
南笙
南笙 2021-02-13 21:12

I\'m having problems making a ComboBox stretch to fill the whole column width in a GridViewColumn. It should also resize when the column is resized.

相关标签:
1条回答
  • 2021-02-13 21:59

    Try setting the Style of the ListViewItem. I also removed your StackPanel.

    <ListView x:Name="MyListView" Margin="0,106,0,0">
        <ListView.Resources>
            <Style TargetType="ListViewItem">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView.Resources>
    
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Num" Width="170">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    
        <ListViewItem></ListViewItem>
    </ListView>
    
    0 讨论(0)
提交回复
热议问题