---
# System prepended metadata

title: WPF .NET Core アプリに MaterialDesignThemes と MahApps を適用する。 2021-05-22
tags: [MaterialDesignThemes, MahApps, .NET Core, WPF]

---

---
lang: ja-jp
breaks: true
---
# WPF .NET Core アプリに MaterialDesignThemes と MahApps を適用する。 2021-05-22

> MahApps.Metro integration
> https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/MahApps.Metro-integration

## App.xaml
```xml=
<Application
・・・
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
・・・
    >
    <Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <!-- MahApps -->
                <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/VS/Colors.xaml" />
                <ResourceDictionary
                    Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Red.xaml" />
                <!--
                -->
                
                <materialDesign:BundledTheme
                    BaseTheme="Light"
                    PrimaryColor="Orange"
                    SecondaryColor="Indigo" />

                <ResourceDictionary
                    Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />

                <!-- Material Design: MahApps Compatibility -->
                <ResourceDictionary
                    Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Fonts.xaml" />
                <ResourceDictionary
                    Source="pack://application:,,,/MaterialDesignThemes.MahApps;component/Themes/MaterialDesignTheme.MahApps.Flyout.xaml" />

                <!-- 独自カスタマイズ -->
                

            </ResourceDictionary.MergedDictionaries>

            <!-- MahApps Brushes -->
            <SolidColorBrush
                x:Key="HighlightBrush"
                Color="{DynamicResource Primary700}" />
            <SolidColorBrush
                x:Key="AccentBaseColorBrush"
                Color="{DynamicResource Primary600}" />
            <SolidColorBrush
                x:Key="AccentColorBrush"
                Color="{DynamicResource Primary500}" />
            <SolidColorBrush
                x:Key="AccentColorBrush2"
                Color="{DynamicResource Primary400}" />
            <SolidColorBrush
                x:Key="AccentColorBrush3"
                Color="{DynamicResource Primary300}" />
            <SolidColorBrush
                x:Key="AccentColorBrush4"
                Color="{DynamicResource Primary200}" />
            <SolidColorBrush
                x:Key="WindowTitleColorBrush"
                Color="{DynamicResource Primary700}" />
            <SolidColorBrush
                x:Key="AccentSelectedColorBrush"
                Color="{DynamicResource Primary500Foreground}" />
            <LinearGradientBrush
                x:Key="ProgressBrush"
                EndPoint="0.001,0.5"
                StartPoint="1.002,0.5">
                <GradientStop
                    Color="{DynamicResource Primary700}"
                    Offset="0" />
                <GradientStop
                    Color="{DynamicResource Primary300}"
                    Offset="1" />
            </LinearGradientBrush>
            <SolidColorBrush
                x:Key="CheckmarkFill"
                Color="{DynamicResource Primary500}" />
            <SolidColorBrush
                x:Key="RightArrowFill"
                Color="{DynamicResource Primary500}" />
            <SolidColorBrush
                x:Key="IdealForegroundColorBrush"
                Color="{DynamicResource Primary500Foreground}" />
            <SolidColorBrush
                x:Key="IdealForegroundDisabledBrush"
                Color="{DynamicResource Primary500}"
                Opacity="0.4" />
            <SolidColorBrush
                x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.OnSwitchBrush.Win10"
                Color="{DynamicResource Primary500}" />
            <SolidColorBrush
                x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.OnSwitchMouseOverBrush.Win10"
                Color="{DynamicResource Primary400}" />
            <SolidColorBrush
                x:Key="MahApps.Metro.Brushes.ToggleSwitchButton.ThumbIndicatorCheckedBrush.Win10"
                Color="{DynamicResource Primary500Foreground}" />

        </ResourceDictionary>
        
    </Application.Resources>
</Application>
```

## MainWindow.xaml
```xml=
<metro:MetroWindow
・・・
    xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"

    TextElement.Foreground="{DynamicResource MaterialDesignBody}"
    TextElement.FontWeight="Medium"
    TextElement.FontSize="14"
    TextOptions.TextFormattingMode="Ideal"
    TextOptions.TextRenderingMode="Auto"
    Background="{DynamicResource MaterialDesignPaper}"
    FontFamily="{DynamicResource MaterialDesignFont}"

    xmlns:metro="http://metro.mahapps.com/winfx/xaml/controls"
    GlowBrush="{DynamicResource AccentColorBrush}"
    BorderThickness="1"
・・・
    >
    <Window.Resources>

        
    </Window.Resources>
    
    <Grid>
        <StackPanel
            Orientation="Vertical">
            <!-- 独自カスタマイズ -->
        </StackPanel>
    </Grid>
</metro:MetroWindow>

```

## MainWindow.xaml.cs
```csharp=
using MahApps.Metro.Controls;

namespace WpfApp10
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}
```

###### tags: `WPF` `.NET Core` `MaterialDesignThemes` `MahApps`
