MessageDialog关闭弹出窗口

MessageDialog关闭弹出窗口

本文介绍了MessageDialog关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的弹出窗口窗口中(包含游戏选项控件),我有重置高分"按钮.按钮触发带有文本块您确定..."和两个按钮是"和否"的 MessageDialog .但是,当MessageDialog打开时,弹出窗口关闭.你知道如何使弹出窗口还活着吗?

in my Popup windows (contains game options control) I have "Reset HighScores" Button. Button fire a MessageDialog with a TextBlock "Are you sure that ..." and two Buttons "Yes" and "No". However, when MessageDialog opens, Popup closes. Do you know how to make popup still alive?

推荐答案

我能够使用Action委托作为MessageDialog关闭时的回调来解决此问题.

I was able to get around this using an Action delegate as a callback for when the MessageDialog is closed.

关键是要在async函数中MessageDialogShowAsync上的await之后调用操作.

The key is to call the Action after an await on MessageDialog's ShowAsync in an async function.

另一个键是关闭并打开弹出窗口,使IsLightDismissEnabled真正生效.

Another key is to Close and Open your popup to get the IsLightDismissEnabled to actually take hold.

XAML:

<Popup
    IsLightDismissEnabled="{Binding IsLightDismiss, Mode=TwoWay}"
    IsOpen="{Binding IsPopupOpen, Mode=TwoWay}">

ViewModel:

ViewModel:

private bool isPopupOpen;
public bool IsPopupOpen
{
    get { return this.isPopupOpen; }
    set { this.SetProperty(ref this.isPopupOpen, value); }
}

private bool isLightDismiss;
public bool IsLightDismiss
{
    get { return this.isLightDismiss; }
    set { this.SetProperty(ref this.isLightDismiss, value); }
}

protected void ShowDialog()
{
    this.IsLightDismiss = false;
    this.IsPopupOpen = false;
    this.IsPopupOpen = true;
    Action showPopup = () => {
        this.IsLightDismiss = true;
        this.IsPopupOpen = false;
        this.IsPopupOpen = true;
    };
    ShowMessageDialog("message", "title", showPopup);
}
private async void ShowMessageDialog(string message, string title, Action callback)
{
    var _messageDialog = new MessageDialog(message, title);
    await _messageDialog.ShowAsync();
    callback();
}

这篇关于MessageDialog关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 13:06