【发布时间】:2019-07-09 18:35:52
【问题描述】:
我有一个 HasUnevenRows = true 的 ListView。
我将 ItemSource 绑定到 ObservableCollection。
这个集合用一些行填充 ListViews。每一行都有不同的高度,因为每一行的文本都不同。
我想知道我是否可以知道每行的高度。
谢谢 亚历山德罗
IEnumerable<PropertyInfo> pInfos = (ListViewPrivacy as ItemsView<Cell>).GetType().GetRuntimeProperties();
var templatedItems = pInfos.FirstOrDefault(info => info.Name == "TemplatedItems");
if (templatedItems != null)
{
var cells = templatedItems.GetValue(ListViewPrivacy);
foreach (ViewCell cell in cells as Xamarin.Forms.ITemplatedItemsList<Xamarin.Forms.Cell>)
{
if (cell.BindingContext != null)
{
System.Diagnostics.Debug.WriteLine("CellHeight = " + cell.Height + " - " + cell.RenderHeight + " " + cell.View.Height + " - " + cell.View.HeightRequest + " - " + cell.View.MinimumHeightRequest + " - " );
Grid grid = (Grid)cell.View;
System.Diagnostics.Debug.WriteLine("Height = " + grid.Height.ToString() + " - " + grid.HeightRequest + " - " + grid.MinimumHeightRequest);
}
}
}
我尝试过使用这样的代码,但我在每个属性中总是“-1”
【问题讨论】: