为什么 Picker 没有填充来自 json web api 的数据 - Xamarin

Why Picker not filled with data from json web api - Xamarin

我试图用来自网络 api

的 json 数据填充选择器
 <Picker x:Name="picker"
        Title="Изберете станция"
        TitleColor="Black">
        </Picker>

在 c# 文件中:

public async Task FillStation_HQ_AHSAsync()
    {
        var result = await _restServiceStations.Get_HQ_AHS(Constants.EndPoint);

        foreach (var item in result)
        {
            var stationsList = new List<string>();
            stationsList.Add(item.ToString());
            picker.ItemsSource = stationsList;
        }
    }

所以结果有超过 200 个项目具有两个属性:“Station”和“Ime”..但是当我点击选择器时他是空的..

构建列表的逻辑很糟糕

var stationsList = new List<string>();  

foreach (var item in result)
{
    stationsList.Add(item.ToString());
}

picker.ItemsSource = stationsList;