MessageDialog弹出关闭(MessageDialog closes Popup)

2019-10-30 17:23发布

在我的弹出窗口(包含游戏选项控制)我有“复位榜”按钮。 按钮火MessageDialog有一个TextBlock“你确定?”和两个按钮“是”和“否”。 然而,MessageDialog打开时,弹出窗口关闭。 你知道如何使弹出还活着吗?

Answer 1:

我可以使用来解决这个Action委托作为当回调MessageDialog关闭。

关键是要调用后行动awaitMessageDialogShowAsyncasync功能。

另一个关键是要关闭和打开弹出来获得IsLightDismissEnabled实际占据上风。

XAML:

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

视图模型:

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();
}


Answer 2:

您设置PopupIsLightDismissEnabled属性为false来实现这一目标。

popup.IsLightDismissEnabled = false;


文章来源: MessageDialog closes Popup