UWP,用于登录的内容对话框

UWP, Content Dialog for Login

如何将内容对话框用作简单的登录屏幕。 当我尝试这样使用它时:

ContentDialog d = new ContentDialog();
        d.Content = contentGrid;
        d.PrimaryButtonText = "aaa";
        d.PrimaryButtonClick += async delegate
        {

        };
await dlg.ShowAsync();

单击按钮时我可以运行 一些逻辑,但它确实隐藏了 EntireDialog。我想展示一些处理动画,并展示一些 "Check" 结果。这可能吗?

是的,这是可能的。这里的关键点是在执行异步操作之前使用 ContentDialogButtonClickEventArgs.GetDeferral method to get a ContentDialogButtonClickDeferral ,然后在异步操作完成时完成延迟。例如:

ContentDialog contentDialog = new ContentDialog();
contentDialog.Content = "Login Test";
contentDialog.PrimaryButtonText = "Login";
contentDialog.PrimaryButtonClick += async (s, args) =>
{
    ContentDialogButtonClickDeferral deferral = args.GetDeferral();

    //Do Some Async Sign In Operation
    await Task.Delay(3000);  //Here I just wait 3 seconds

    deferral.Complete();
};
await contentDialog.ShowAsync();

还有一个示例显示了如何创建和使用从 ContentDialog 派生的自定义对话框 (SignInContentDialog) Examples[=20] =] ContentDialog class 中的部分。你可以检查一下。