I am writing an application in Xamarin.Forms for Android, iOS, and Windows Store. I want to populate a ListView with about 10,000 elements from an XML file. The problem is when I run the code for Windows Phone or Windows Store, the application lags for about a minute before coming back alive and populating the ListView. It populates instantly for Android and iOS. However for Windows, it lags. Could somebody help me fix this problem? Here is my code which does the reading of XML and populating the ListView:
public async void LoadCharacters() { Assembly assembly = typeof(CharacterPage).GetTypeInfo().Assembly; string file = assembly.GetManifestResourceNames().First(x => x.Contains("Characters.xml")); Stream stream = assembly.GetManifestResourceStream(file); data = new ObservableCollection<Character>(); await Task.Factory.StartNew(delegate { XDocument doc = XDocument.Load(stream); IEnumerable<Character> characters = from query in doc.Descendants("c") select new Character { Simplified = query.Attribute("s").Value, Traditional = query.Attribute("t").Value, Pinyin = query.Attribute("p").Value, English = query.Attribute("e").Value, URL = query.Attribute("u").Value }; data = characters.ToObservableCollection(); }); characterList.ItemsSource = data; }
This code works, and runs smooth in iOS and Android. However in Windows, it hangs for about 1 minutes. Please help.
Thank you
No comments:
Post a Comment