XML을 다운로드하고 데이터를 collectionA
으로 정렬하는 방법이 있습니다. 그런 다음 collectionA
을 2 개의 작은 콜렉션으로 분할하여 collectionB
& collectionC
두 개의 목록을 채 웁니다. 이제 문제는 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 population을 호출하는 코드를 추가하면 완료되기 전에 완료를 말한 이유를 알 수 있습니다. –