MahApp MessageDialog 隐藏

MahApp MessageDialog Hide

我正在使用两个线程,一个将在 WPF

中使用 MahApps MessageDialog 向用户提问

另外我想隐藏MessageDialog,如何在下面的代码中HideMessageDialog()隐藏MessageDialog?

我正在做一些需要打断问题的事情,同时保持主 window 打开。所以我需要一种在对话框真正显示后隐藏对话框的方法。

    public void Execute()
    {
        Task showAsk = new Task(ShowAskingDialog);
        Task hideAsk = new Task(HideAskingByCode);

        showAsk.Start();
        hideAsk.Start();
    }

    public async void ShowAskingDialog()
    {
        Thread.Sleep(3000);

        this.MetroDialogOptions.ColorScheme = MetroDialogColorScheme.Accented;
        var msgbox_settings = new MetroDialogSettings { 
        AffirmativeButtonText = "I know", NegativeButtonText = "I don't know" };

        // puase at asking MessaageDialog
        var isKnow = await this.ShowMessageAsync(
                    "Question", "Do you know WPF?", 
                    MessageDialogStyle.AffirmativeAndNegative, msgbox_settings);

    }

    public void HideAskingByCode()
    {
        Thread.Sleep(5000);

        //How to Hide the MessageDialog by code, not by user click Button?
        HideMessageDialog();
    }


MessageDialog 将像这样显示,嵌入到 Main Window:

感谢@Nobody 和

隐藏MessageDialog可以使用通用HideMetroDialogAsync():

public void HideMessageDialog ()
{    
     this.Dispatcher.Invoke(
        async () =>{

            BaseMetroDialog dialogBeingShow = 
                await this.GetCurrentDialogAsync<BaseMetroDialog>();

            //Hide Current Single Dialog
            if(dialogBeingShow != null)
                await this.HideMetroDialogAsync(dialogBeingShow);

            //Or Hide All Dialogs
            while (dialogBeingShow != null)
            {
               await this.HideMetroDialogAsync(dialogBeingShow);
               dialogBeingShow = 
                   await this.GetCurrentDialogAsync<BaseMetroDialog>();
            }

                }
             );
}