How can I make a column in a listbox in WPF the same width for all items?

前端 未结 1 1669
予麋鹿
予麋鹿 2020-12-13 02:02

I have a ListBox with an ItemTemplate consisting of a TextBlock and a ComboBox. The problem is that the width of the text

相关标签:
1条回答
  • 2020-12-13 02:36

    You can use the IsSharedSizeScope attached property. In your template definition, attach a "shared size group" to each column, like this:

    <Grid.ColumnDefinitions>
        <ColumnDefinition SharedSizeGroup="col1" />
        <ColumnDefinition SharedSizeGroup="col2" />
    </Grid.ColumnDefinitions>
    

    ... then define your ListBox as a shared size scope so it knows to size each "size group" the same way:

    <ListBox Grid.IsSharedSizeScope="True">...</ListBox>
    
    0 讨论(0)
提交回复
热议问题