Metro MahApps MessageBox 主题

Metro MahApps MessageBox theme

也许有人可以告诉我如何正确地将 Async 消息实现到 Metro window 它会具有应用程序的当前主题和口音?

演示示例中的代码有效,但主题和重音保持默认:

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。我做错了什么?

我已经尝试了您的代码,它正在运行。我只在 Button_Click 中转换了 MenuItem_Click 但它是无关紧要的。

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

而不是最初的

我有 Window1.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"
    >

以及 App.xaml

中的资源
    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>

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

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