我试图实现一个输入对话框,但是当我点击确定或取消时,我似乎无法弄清楚为什么我会遇到线程问题。
以下是我创建对话框并显示对话框的代码段,我查看了一些示例并回答但是我无法弄清楚我在这里做错了什么。
var metroDialogSettings = new MetroDialogSettings()
{
AffirmativeButtonText = "OK",
NegativeButtonText = "CANCEL",
AnimateHide = true,
AnimateShow = true,
ColorScheme = MetroDialogColorScheme.Accented,
};
var dialog = new AddStorageAccountDialog(MainWindowHelper.mainWindow, metroDialogSettings);
await Application.Current.Dispatcher.Invoke(async () =>
{
await MainWindowHelper.mainWindow.ShowMetroDialogAsync(dialog);
await dialog.WaitForButtonPressAsync().ContinueWith((m) =>
{
MainWindowHelper.mainWindow.HideMetroDialogAsync(dialog);
});
var displayname = dialog.DisplayName;
var accountname = dialog.AccountName;
var accountkey = dialog.AccountKey;
});