我有一种方法是下载XML并将其数据分类到collectionA
。然后我将collectionA
拆分为2个较小的集合,collectionB
& collectionC
其中填充了2个列表。现在我遇到的问题是填充和拆分collectionA
的方法正在完成之前,collectionA
有时间填充本身。加载页面后的加载方法
我该如何去制作collectionB
& collectionC
等到collectionA
被填充?
方法填充collectionA
public void downloadXML(bool data)
{
if (data == false)
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("http://ec.urbentom.co.uk/studentAppData.xml"));
}
}
private void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
setupDictionary();
MainPage page = new MainPage();
if (e.Error != null)
return;
XElement xmlitems = XElement.Parse(e.Result);
List<XElement> elements = xmlitems.Descendants("item").ToList();
List<StudentGuideModel> moveItems = new List<StudentGuideModel>();
foreach (XElement c in elements)
{
StudentGuideModel _item = new StudentGuideModel();
_item.Title = c.Element("Title").Value;
_item.Description = c.Element("Description").Value;
_item.Phone = c.Element("Phone").Value;
_item.Email = c.Element("Email").Value;
_item.Category = c.Element("Category").Value;
_item.Image = c.Element("Image").Value;
_item.SmallInfo = c.Element("SmallInfo").Value;
_item.Image = getImage(_item.Image);
allData.Add(_item);
}
MessageBox.Show("Download Complete", "Loaded", MessageBoxButton.OK);
}
方法填充collectionB
& collectionC
public ObservableCollection<StudentGuideModel> splitCategories(string catName)
{
ObservableCollection<StudentGuideModel> catItems = new ObservableCollection<StudentGuideModel>();
foreach (var item in allData)
{
if (item.Category == catName)
{
catItems.Add(item);
}
}
return catItems;
}
名单的人口使用collectionB
& collectionC
faciliiesList.ItemsSource = App.getControl.splitCategories("Facilities");
contactPanel.ItemsSource = App.getControl.splitCategories("Contacts");
请添加调用b和c的tge填充的代码,这样我们就可以看到为什么在完成填充之前完成填充 –