我无法将异步数据绑定到文本块。
当我使用 F11 逐步完成我的代码时,它可以工作。但是当我只是运行我的应用程序时,它会抛出一个错误说:
Value cannot be null.
看起来代码运行得太快了。
这是我的代码:
settings.GetSettings();
tbNamePlayer1.Text = settings.player1;
tbNamePlayer2.Text = settings.player2;
获取设置方法:
StorageFolder sf = await Package.Current.InstalledLocation.GetFolderAsync("XML");
StorageFile st;
try {
st = await sf.GetFileAsync(filename);
} catch {
WriteInitialSettings();
}
st = await sf.GetFileAsync(filename);
var reader = XmlReader.Create(st.Path);
XmlSerializer ser = new XmlSerializer(typeof(Settings));
settings = (Settings)ser.Deserialize(reader);
player1 = settings.player1;
player2 = settings.player2;
difficulty = settings.difficulty;
win = settings.win;
lose = settings.lose;