Category / Section
How to set AtomationID for ListViewItem in SfListView?
1 min read
The SfListView items can be automat in application level by setting the AutomationId. It can be set using ItemAppearing event for the ListViewItem like below code snippet.
C#
public partial class GroupingPage : ContentPage { public GroupingPage() { InitializeComponent(); listView.ItemAppearing += ListView_ItemAppearing; } private void ListView_ItemAppearing(object sender, ItemAppearingEventArgs e) { var layout = listView.LayoutManager as LinearLayout; var rowItems = layout.GetType().GetRuntimeFields().First(p => p.Name =="items").GetValue(layout) as IList; foreach (ListViewItemInfo iteminfo in rowItems) { if (iteminfo.Element != null && iteminfo.Element.AutomationId == null) iteminfo.Element.AutomationId = "ID"; } } }