如何在Xamarin.Forms中为Listview标签的自动化ID添加增量值? [英] How to add incremental value for the automation id of a Listview label in Xamarin.Forms?
问题描述
我有这样的资源
<ContentPage.Resources>
<ResourceDictionary>
<x:String x:Key="LabelAutomationIdentifier">LBL_</x:String>
</ResourceDictionary>
</ContentPage.Resources>
我的列表视图看起来像
<ListView
ItemsSource="{Binding ListItemSource}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label
AutomationId="{StaticResource LabelAutomationIdentifier, StringFormat {0}_{Incremental Value OR UniqueIdentifier}'}"
Text="{Binding Title}" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
如何在自动化ID中添加增量值?
How to add the incremental value in the automation id?
推荐答案
创建对象时无法创建?例如:var _id = 0;
MenuItems = new ObservableCollection<MenuItem>
{
new MenuItem
{
Id = _id++;
Title = "xxxxxxxx",
},
new MenuItem
{
Id = _id++;
Title = "yyyyyyyyy",
},
new MenuItem
{
Id = _id++;
Title = "zzzzz",
},
new MenuItem
{
Id = _id++;
Title = "jjjj",
},
};
you can't make when you create the objects??? For example : var _id = 0;
MenuItems = new ObservableCollection<MenuItem>
{
new MenuItem
{
Id = _id++;
Title = "xxxxxxxx",
},
new MenuItem
{
Id = _id++;
Title = "yyyyyyyyy",
},
new MenuItem
{
Id = _id++;
Title = "zzzzz",
},
new MenuItem
{
Id = _id++;
Title = "jjjj",
},
};
这篇关于如何在Xamarin.Forms中为Listview标签的自动化ID添加增量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!