WPF 套用Metro樣式

Posted by Leo Yang on 2020-07-02

Nuget安裝MahApps相關套件

1
2
3
MahApps.Metro.IconPacks
MahApps.Metro.Metro
MahApps.Metro.Resources

主程式(MainWindow.xaml)套用MahApp樣式

Xaml

1
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"

CodeBehind

WindowName:MetroWindow
1
2
3
using MahApps.Metro.Controls;

public partial class WindowName:MetroWindow

調整App.xaml

加入樣式

1
2
3
4
5
6
7
8
9
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<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" />
<<<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>

結果

Mahapps