2016-04-26 94 views
1

也許有人可以告訴我如何在Metro窗口中正確實現異步消息,它將具有應用程序的當前主題和口音?Metro MahApps MessageBox主題

從演示樣本作品所採取的代碼,但主題和重點依然默認:

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。我究竟做錯了什麼?

回答

0

我試過你的代碼,它工作。我只改變了Button_Click中的MenuItem_Click,但它是無關緊要的。

我得到黑色的背景和像下面這樣的紅色退出,iff我點擊設置按鈕後關閉應用程序。

enter image description here

,而不是最初的

enter image description here

我有標準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> 

和資源

+0

好像沒有默認值(樣式/口音/ Blue.xaml,樣式/口音/ BaseLight.xaml)來源 在App.xaml中,帶主題的MessageBox不起作用。我只需要添加這些。謝謝。 – Beldrak

+0

是的,您必須在App.xaml中添加上面顯示的資源。我很高興能夠提供幫助 – 2016-04-27 09:21:16

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中