|
public class Behavior : Behavior<ContentPage>
{
SfListView ListView;
protected override void OnAttachedTo(ContentPage bindable)
{
ListView = bindable.FindByName<SfListView>("listView");
ListView.SelectionChanging += ListView_SelectionChanging;
base.OnAttachedTo(bindable);
}
private void ListView_SelectionChanging(object sender, ItemSelectionChangingEventArgs e)
{
var group = GetGroup(e.AddedItems[0]);
var index = ListView.DataSource.DisplayItems.IndexOf(group);
ListView.LayoutManager.ScrollToRowIndex(ListView.DataSource.DisplayItems.IndexOf(group), Syncfusion.ListView.XForms.ScrollToPosition.Start);
}
public GroupResult GetGroup(object itemData)
{
GroupResult itemGroup = null;
foreach (var item in this.ListView.DataSource.DisplayItems)
{
if (item is GroupResult)
itemGroup = item as GroupResult;
if (item == itemData)
break;
}
return itemGroup;
}
} |
|
ItemTappedEventArgs |
Description |
|
It gets the type of the tapped item. | |
|
The underlying data associated with the tapped item as its arguments. | |
|
Gets the touch position in the tapped item. |
|
public class Behavior : Behavior<ContentPage>
{
SfListView ListView;
GroupResult Group;
protected override void OnAttachedTo(ContentPage bindable)
{
ListView = bindable.FindByName<SfListView>("listView");
ListView.ItemTapped += ListView_ItemTapped;
base.OnAttachedTo(bindable);
}
private void ListView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
var index = 0;
if (e.ItemType == ItemType.GroupHeader)
{
index = ListView.DataSource.DisplayItems.IndexOf(e.ItemData);
}
else if (e.ItemType == ItemType.Record)
{
Group = GetGroup(e.ItemData);
index = ListView.DataSource.DisplayItems.IndexOf(Group);
}
ListView.LayoutManager.ScrollToRowIndex(index, Syncfusion.ListView.XForms.ScrollToPosition.Start);
App.Current.MainPage.DisplayAlert("Group Header Key", "" + Group.Key, "Ok");
}
public GroupResult GetGroup(object itemData)
{
GroupResult itemGroup = null;
foreach (var item in this.ListView.DataSource.DisplayItems)
{
if (item is GroupResult)
itemGroup = item as GroupResult;
if (item == itemData)
break;
}
return itemGroup;
}
#endregion
} |