Articles in this section
Category / Section

How to set AtomationID for ListViewItem in SfListView?

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"; 
            } 
        } 
} 
 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied