0
votes

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
e.ItemData is not an IEnumerable. It is just single value from your List, not all values - Jason
This is a good example of the difference between direct casting and casting with as keyword. With (IEnumerable<ListViewCall>)e.ItemData; you would've received a runtime exception and had a better clue of what's wrong but with as you just get a null if the cast is invalid, no exception. - Timo Salomäki
Thank you for response but this cast is invalid! - Hessam

2 Answers

0
votes

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
votes
           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;
        //}


    }