关于wpf:Metro MahApps MessageBox主题

Metro MahApps MessageBox theme

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

演示示例中的代码有效,但主题和重点仍然是默认设置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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();
    }

当我简单地更改主题时:

1
2
3
4
5
6
7
 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。 我究竟做错了什么?


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



在App.xaml中


我已经尝试过您的代码,并且可以正常工作。 我仅将ButtonItem_Click中的MenuItem_Click转换了,但这无关紧要。

如果单击设置按钮后关闭了应用程序,我将得到黑色背景和红色"退出",如下所示。

enter image description here

而不是最初的

enter image description here

我有标准的Window1.xaml开头

1
2
3
4
5
6
7
<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"
    >

以及App.xaml中的资源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
        <!-- Accent and AppTheme setting -->
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>