Тема Metro MahApps MessageBox

Может быть, кто-нибудь может показать мне, как правильно внедрить асинхронное сообщение в окно 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 по умолчанию. Что я делаю неправильно?


person Beldrak    schedule 26.04.2016    source источник


Ответы (2)


Я попробовал ваш код, и он работает. Я только преобразовал MenuItem_Click в Button_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>
person Community    schedule 26.04.2016
comment
Вроде как без дефолтных (Styles/Accents/Blue.xaml, Styles/Accents/BaseLight.xaml) Sources в App.xaml MessageBox с темой не работает. Мне просто нужно было добавить их. Спасибо. - person Beldrak; 27.04.2016
comment
Да, вы должны добавить показанные выше ресурсы в App.xaml. Я рад, что смог помочь - person ; 27.04.2016

Мне просто нужно было добавить словари ресурсов по умолчанию

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

person Beldrak    schedule 27.04.2016