[英]Why call to ContentDialog.ShowAsync() hangs
為什么以下代碼(感謝Aybe )掛起在行var result = await dialog1.ShowAsync();
我希望它能得到一個簡單的用戶輸入,並在用戶點擊OK后繼續。 但是對話框UI甚至沒有完全顯示出來。 它只是掛着所有的白色背景。 我只是在主窗口頂部看到一個帶有白色背景的小對話窗口,它只是掛在那里。
我已經看到過像這里這樣的問題的解決方案。 但是這個解決方案建議我在Button_Click事件上使用async
。 引用的解決方案與我的解決方案之間的區別在於我使用的是UWP
而它們可能不是。 那么,我可能缺少什么以及我們如何解決這個問題?
private async void myButton_ClickAsync(object sender, RoutedEventArgs e)
{
var dialog1 = new ContentDialog1();
var result = await dialog1.ShowAsync(); //hangs here
if (result == ContentDialogResult.Primary)
{
var text = dialog1.Text;
}
....
....
}
自定義對話框類 :
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace App1
{
public sealed partial class ContentDialog1 : ContentDialog
{
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof (string), typeof (ContentDialog1), new PropertyMetadata(default(string)));
public ContentDialog1()
{
InitializeComponent();
}
public string Text
{
get { return (string) GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
}
}
}
更新 :
我正在使用VS2017
和Windows 10 Professional
筆記本電腦的最新版本。 不涉及攻絲(觸摸設備)或智能手機或平板電腦。
在完成你所做的工作時,我能夠成功地顯示對話框。
在提供的代碼中有一些我們沒有看到的東西,或者是因為它工作得很好。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.