WPF GridViewColumn Width=“auto” only works for items in the current scroll scope

前端 未结 1 1060
不知归路
不知归路 2021-01-13 11:40

I have a ListView that contains many items and am trying to set the column widths to auto so that they auto-expand to the width of the longest string in the column. At firs

相关标签:
1条回答
  • 2021-01-13 12:26

    The reason is that virtualization prevents some items from being generated, and then they are not considered for the calculation of the width.

    So you can switch off the virtualization for the ListView with adding this to it ->

    <ListView x:Name="lv" ScrollViewer.CanContentScroll="False">
    

    But be careful it can slow down your app, if you have a lot of items, as they all will be generated at startup.

    0 讨论(0)
提交回复
热议问题