【发布时间】:2016-10-20 06:14:04
【问题描述】:
我正在 Xamarin.Forms 中为 Android、iOS 和 Windows 应用商店编写应用程序。我想用 XML 文件中的大约 10,000 个元素填充 ListView。问题是,当我运行 Windows Phone 或 Windows Store 的代码时,应用程序会延迟大约一分钟,然后才能恢复活动并填充 ListView。它会立即为 Android 和 iOS 填充。但是对于 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 分钟。请帮忙。
谢谢
【问题讨论】:
标签: c# android xml listview xamarin.forms