Search code examples
mahapps.metroapp.xaml

Mahapps metro themes not available as no app.xaml


I am working on an Office Add-In and wanted to add a WPF Mahapps Windows.

Everything went well, but I cannot apply the Mahapps Windows style.
Looking at the tutorial here I see that I update the App.xaml to add the various themes. As it is not a WPF project, I don't have the App.xaml.

What is the most efficient way to apply the style?
Can I do it directly at the Windows level?
Or do I need to manually create an App.xaml?


Solution

  • You can put all the MahApps.Metro resources also inside a Window resource tag like

    <Controls:MetroWindow x:Class="StyledWindow"
                          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                          xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls">
      <Window.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>
      </Window.Resources>
    
      <Grid>
      </Grid>
    </Controls:MetroWindow>
    

    Hope that helps!