2016-04-26 9 views
1

Vielleicht könnte mir jemand zeigen, wie Async-Nachricht korrekt in Metro-Fenster zu implementieren, dass es aktuelle Thema und Akzent der Anwendung hätte?Metro MahApps MessageBox Thema

Die von den Demo-Beispiel funktioniert genommen Code, aber Thema und Akzent bleiben default:

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(); 
    } 

Wenn ich einfach das Thema wechseln:

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); 
    } 

ich die weißen und blauen MessageBox Standard erhalten. Was mache ich falsch?

Antwort

0

Ich habe Ihren Code ausprobiert und es funktioniert. Ich habe nur das MenuItem_Click in einem Button_Click umgewandelt, aber es ist irrelevant.

Ich bekomme den schwarzen Hintergrund und ein rotes Quit wie unten, iff Ich schließe die App nach dem Klicken auf die Schaltfläche Einstellungen.

enter image description here

anstelle des ursprünglichen

enter image description here

habe ich die Standard-Window1.xaml beginnend mit

<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" 
    > 

und die Ressourcen in der 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> 
+0

Es scheint so, ohne den Standardwert (Styles/Akzente/Blue.xaml, Styles/Akzente/BaseLight.xaml) Quellen nur erforderlich hinzufügen In der App.xaml funktioniert die MessageBox mit Thema nicht. Ich musste nur diese hinzufügen. Vielen Dank. – Beldrak

+0

Ja, Sie müssen die oben angezeigten Ressourcen in der App.xaml hinzufügen. Ich bin froh, dass ich helfen konnte –

0

ich die Standard-Ressourcen Wörterbücher

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