如何在windows phone app的组合框中快速绑定数据?

时间:2015-11-28 10:35:40

标签: windows-phone-8 combobox windows-phone-8.1

您好我正在开发一个应用程序。在我的应用程序中有2000个城市。这些城市来自webservice.Now我想要很快地将这些城市绑定到组合框架。实际上,绑定数据需要5分钟时间。数据非常快请帮助我。

以下是我的代码:

  var busclient = new NewReloadApp.JsonWebClient();

             var Busresp1 = await busclient.DoRequestAsync(Url.weburl + "getCities");
                    string Busresult1 = Busresp1.ReadToEnd();
                    JArray BusjsonArray = JArray.Parse(Busresult1);

                    for (int j = 0; j < BusjsonArray.Count; j++)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(0.01));
                        JObject jobj = (JObject)BusjsonArray[j];

                        string id = (string)jobj["cityid"];
                        string cityname = (string)jobj["cityname"];



                        city cit = new city();
                        cit.cityname = cityname;

                        Fromcityname1.Items.Add(cityname);
                        Tocityname1.Items.Add(cityname);
                        Db_Helper.Insert(new Buscities(id, cityname));
                        UserProfileList.Add(cit);

这里Fromcityname1,Tocityname1是组合框。

1 个答案:

答案 0 :(得分:2)

List<string> Fromcityname = new List<string>();
Fromcityname.Add(cityname);
Fromcityname1.ItemSources = Fromcityname;

和xaml

<ComboBox x:name="Fromcityname1" ItemSources="{binding}"/>

Fromcityname.SetBinding(ComboBox.ItemsSourceProperty, new Binding { Source = Fromcityname});