如何使ListBox内的ListBoxItems具有相同的高度?
<ListBox
HorizontalContentAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
>
<ListBoxItem><TextBlock TextWrapping="Wrap">Long text that would wrap and increase height of single ListBoxItem</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock TextWrapping="Wrap">Short text</TextBlock></ListBoxItem>
<ListBoxItem><TextBlock TextWrapping="Wrap">Short text</TextBlock></ListBoxItem>
</ListBox>
我希望具有“短文本”的项目与第一个项目具有相同的高度(由于换行,通常会具有更多行)。
最佳答案
我在这里有点作弊,但试试这个:
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="{Binding Path=Items.Count, RelativeSource={RelativeSource AncestorType=ListBox}}" VerticalAlignment="Top"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem>
<TextBlock TextWrapping="Wrap">Long text that would wrap and increase height of single ListBoxItem</TextBlock>
</ListBoxItem>
<ListBoxItem>
<TextBlock TextWrapping="Wrap">Short text</TextBlock>
</ListBoxItem>
<ListBoxItem>
<TextBlock TextWrapping="Wrap">Short text</TextBlock>
</ListBoxItem>
关于wpf - wpf 中相同大小的列表框项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12998300/