我有一个我想要实现的自定义ItemView,我想将事件提升回作为父项的ListView。我该怎么做呢?
例如我的ItemView有。如何让ListView所有者调用事件?
public partial class MyItemView : ContentView, INotifyPropertyChanged
{
}
答案 0 :(得分:1)
您可以通过迭代View的父级来获取ListView项目中的ListView,直到我们获得ListView。
public partial class MyItemView : ContentView, INotifyPropertyChanged
{
ListView listView;
protected override void LayoutChildren(double x, double y, double width, double height)
{
base.LayoutChildren(x, y, width, height);
Element list = this;
while(list.GetType() != typeof(ListView))
{
list = list.Parent;
}
listView = list as ListView;
}
}