MahApp MessageDialog隐藏

时间:2017-09-13 05:37:42

标签: wpf mahapps.metro

我正在使用两个主题,一个会在WPF中使用 MahApps MessageDialog 询问用户问题,

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

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

    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将显示如下,嵌入在主窗口中:

enter image description here

1 个答案:

答案 0 :(得分:0)

感谢@Nobody和the answer

隐藏MessageDialog可以使用常规validateSavedRecord()

HideMetroDialogAsync()