MessageDialog closes Popup

ぃ、小莉子 提交于 2019-12-11 17:48:51

问题


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?


回答1:


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

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

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:

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



回答2:


set your Popup's IsLightDismissEnabled property to false to achieve that.

popup.IsLightDismissEnabled = false;


来源:https://stackoverflow.com/questions/13323752/messagedialog-closes-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!