ListView动态改变每一项的高度。

时间:2022-08-17 16:09:37

ListView中每一项的高度默认是相同的,除非超过其预定高度值,否则需要动点手脚。

VariableSizedListView 继承 ListView
然后重写
protected override void PrepareContainerForItemOverride(DependencyObject element,
            object item)
{
var localItem = item as HeadingItem;
var lvi = element as ListViewItem;
lvi.Height = 28;//这样就修改了高度
                        lvi.Margin = new Thickness(0, 20, 0, 0);//
}