Metro MahApps MessageBox主题

时间:2016-04-26 16:44:55

标签: wpf mahapps.metro

也许有人可以告诉我如何在Metro窗口中正确实现异步消息,它将具有应用程序的当前主题和重音?

从演示示例中获取的代码有效,但主题和重音仍然是默认值:

private async void ClosingApp(object sender, System.ComponentModel.CancelEventArgs e)
    {
        e.Cancel = !_shutdown;
        if (_shutdown) return;
        var mySettings = new MetroDialogSettings()
        {
            AffirmativeButtonText = "Quit",
            NegativeButtonText = "Cancel",
            AnimateShow = true,
            AnimateHide = false
        };
        var result = await this.ShowMessageAsync("Quit application?",
            "Sure you want to quit application?",
            MessageDialogStyle.AffirmativeAndNegative, mySettings);

        _shutdown = result == MessageDialogResult.Affirmative;
        if (_shutdown)
            Application.Current.Shutdown();
    }

当我改变主题时:

 private void MenuItem_Click(object sender, RoutedEventArgs e)
    {
        // set the Red accent and dark theme only to the current window
        var theme = ThemeManager.GetAppTheme("BaseDark");
        var accent = ThemeManager.GetAccent("Red");
        ThemeManager.ChangeAppStyle(Application.Current, accent, theme);
    }

我得到默认的白色和蓝色MessageBox。我做错了什么?

2 个答案:

答案 0 :(得分:0)

我已经尝试过你的代码而且它正在运行。我只是在Button_Click中改变了MenuItem_Click,但它无关紧要。

我正在获得黑色背景和下面的红色Quit, iff 点击设置按钮后关闭应用程序。

enter image description here

而不是最初的

enter image description here

我有标准的Window1.xaml,以

开头
parent

和App.xaml中的资源

<Controls:MetroWindow x:Class="TestFrontend.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
        Closing="App_Closing"
    Title="Test" Height="600" Width="600"
    >

答案 1 :(得分:0)

我只需要添加默认的资源字典

<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" /> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" /> 在App.xaml