Xamarin.Forms - 强制重绘 ListView 布局 [英] Xamarin.Forms - Force ListView layout to redraw
问题描述
我有一个带有 HasUnevenRows = true
的 ListView,其中每个单元格的内容开始时都是变体,但内容也可以即时更改(通过单击单元格中的按钮).当 ListView 最初加载时,系统必须执行计算,以便根据每个单元格的内容正确确定和绘制每个单元格的高度.
I have a ListView with HasUnevenRows = true
, where the content of each cell is variant to begin with, but the content can also change on the fly (through clicking of a button in the cell). When the ListView initially loads, the system must perform a calculation in order to correctly determine and draw the heights of each cell based on their content.
但是当我在初始加载后更新内容时,显然没有完成同样的计算,因为单元格的高度不会改变——直到我将该项目滚动到视野之外然后回到视野中.
But when I update the content after the initial load, this same calculation is apparently not done, because the height of the cell does not change -- until I've scrolled that item out of view and then back into view.
如何在不完全刷新 ListView 的情况下强制执行相同的计算并手动重绘?
我尝试将 ListView 包装在框架中并在框架上调用 .ForceLayout()
,但没有成功.
I tried wrapping the ListView in a Frame and calling .ForceLayout()
on the frame, but no luck.
推荐答案
默认情况下不会重新计算单元格的高度,因为这是一个昂贵的过程.如果您想强制重新调整大小,您需要在单元格上调用 ForceUpdateSize().
The height of the cells aren't recalculated by default because it is an expensive process. If you want to force a re-size you need to call ForceUpdateSize() on the cell.
注意:这不适用于旧版本的 Xamarin Forms.它是在 2.0.0.0 中添加的,但尝试更新到至少 2.2.0.31
NOTE: This does not work on older versions of Xamarin Forms. It was added in 2.0.0.0, but try updating to at least 2.2.0.31
这篇关于Xamarin.Forms - 强制重绘 ListView 布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!