xamarin forms syncfusion ListView ItemAppearing

222 views Asked by At

I use syncfusion listview to create listview on xamarin forms

I want to use the ItemAppearing option in listview

I used this EXAMPLE on website:https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView.html

and this EXAMPLE: https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView~ItemAppearing_EV.html#ExampleBookmark

I use this example and found this problem

ListView.ItemAppearing +=listView_ItemAppearing;

public void listView_ItemAppearing(object sender, Syncfusion.ListView.XForms.ItemAppearingEventArgs e)
        {
           var temp= e.ItemData as IEnumerable<ListViewCall>;
            //temp.ToList();
        }

I cast e.ItemData to List<ListViewCall> and get null

e.ItemData has data but var temp is null

Why would this be?

2

There are 2 answers

0
Leo Zhu On

ItemData :Gets the underlying data object of the ListViewItem when item appearing from the bound data source.

so e.ItemData will return you the binding object. like the example above,it will return the object BookInfo.

public void listView_ItemAppearing(object sender, Syncfusion.ListView.XForms.ItemAppearingEventArgs e)
    {
       var temp= e.ItemData as BookInfo;           
    }
0
Hessam On
           public void listView_ItemAppearing(object sender, Syncfusion.ListView.XForms.ItemAppearingEventArgs e)
    {
        if (e.ItemData is GroupResult)
        {
            var listViewCalls = (e.ItemData as GroupResult).Items as EnumerableQuery<ListViewCall>;
            foreach (var listViewCall in listViewCalls)
            {

            }
        }
        else if (e.ItemData is ListViewCall)
        {
            var listViewCall = e.ItemData as ListViewCall;


        }


        // foreach (Object obj in e.ItemData.GetType().GetProperties(System.Reflection.BindingFlags.Public | BindingFlags.Instance))
        // {
        //    string s = (obj as Call).Title;
        //}


    }