Xamarin.Forms-强制重新绘制ListView布局 [英] Xamarin.Forms - Force ListView layout to redraw

查看:460
本文介绍了Xamarin.Forms-强制重新绘制ListView布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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的情况下强制执行相同的计算并手动重绘?

How can I force this same calculation and redraw manually, without completely refreshing the 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆