I am stuck on how to show items from a list in a picker.
I can use a for loop and add the items to the Picker, is there any other way ? I have to also use bound values from the list. All I get right now is the type and not the ID or Category name i need.
private async void GetCategories(string url)
{
//get json as a string
var result = await _clientHttp.GetStringAsync(url);
var json = JsonConvert.DeserializeObject<List<CategoryList>>(result);
List<CategoryList> tempList = new List<CategoryList>();
foreach (var items in json)
{
tempList.Add(new CategoryList{CatId = items.CatId,category = items.category});
}
;
PickerCategory.ItemsSource = tempList;
}
You must override your CategoryList.ToString()
method to display the appropriate values:
class CategoryList{
public string category {get;set;}
public override string ToString(){
return category;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.