2016-10-20 56 views
0

我正在爲Android,iOS和Windows Store的Xamarin.Forms編寫應用程序。我想用一個XML文件中的大約10,000個元素來填充一個ListView。問題是,當我運行Windows Phone或Windows Store的代碼時,應用程序滯後大約一分鐘才返回活動並填充ListView。它爲Android和iOS即時填充。但是,對於Windows,它滯後。有人能幫我解決這個問題嗎?這裏是我讀取XML和填充ListView的代碼:Xamarin.Forms Windows應用程序將XML數據加載到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; 
    } 

此代碼有效,在iOS和Android上運行流暢。但是,在Windows中,它會掛起大約1分鐘。請幫忙。

謝謝

回答

0

答案是設置listview項的高度。然後它立即加載。

相關問題