【发布时间】:2020-02-26 23:34:29
【问题描述】:
我使用 syncfusion listview 在 xamarin 表单上创建列表视图
我想在列表视图中使用 ItemAppearing 选项
我用这个例子发现了这个问题
ListView.ItemAppearing +=listView_ItemAppearing;
public void listView_ItemAppearing(object sender, Syncfusion.ListView.XForms.ItemAppearingEventArgs e)
{
var temp= e.ItemData as IEnumerable<ListViewCall>;
//temp.ToList();
}
我将e.ItemData 转换为List<ListViewCall> 并得到null
e.ItemData 有数据,但 var temp 是 null
为什么会这样?
【问题讨论】:
-
e.ItemData 不是 IEnumerable。它只是您列表中的单个值,而不是所有值
-
这是一个很好的例子,说明了直接投射和使用
as关键字投射之间的区别。使用(IEnumerable<ListViewCall>)e.ItemData;,您会收到运行时异常,并且可以更好地了解问题所在,但使用as,如果强制转换无效,您只会得到一个空值,没有例外。 -
感谢您的回复,但此演员阵容无效!
标签: xamarin xamarin.forms cross-platform syncfusion xamarin.forms-styles