您能够经过NuGet GUI(右键单击您的项目,单击Manage NuGet Packages,选择Online并搜索MahApps.Metro)或使用Package Manager控制台安装MahApps.Metro。c#
PM> Install-Package MahApps.Metro
或使用软件包管理器控制台:app
PM> Install-Package MahApps.Metro -Pre
您能够使用两种方法使用MahApps.Metro设置Window的样式:spa
安装MahApps.Metro以后:code
MainWindow.xaml
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
标签更改成
(请记住也要更改结束标签!)您应该有相似如下内容(请勿复制和粘贴):component
<Controls:MetroWindow x:Class="WpfApplication.MainWindow" 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" Title="MainWindow" Height="600" Width="800"> <!-- your content --> </Controls:MetroWindow>
您还须要修改MainWindow.xaml.cs
文件,以使其基类MainWindow
与MetroWindow
XAML文件的类匹配。xml
// To access MetroWindow, add the following reference using MahApps.Metro.Controls; namespace WpfApplication { public partial class MainWindow : MetroWindow { public MainWindow() { InitializeComponent(); } } }
可是在大多数状况下,您能够删除基类(由于这是partial
XAML应该处理的类):资源
namespace WpfApplication { public partial class MainWindow { public MainWindow() { InitializeComponent(); } } }
MahApp.Metro的全部资源都包含在单独的资源词典中。为了使大多数控件采用MahApps.Metro主题,您须要将ResourceDictionaries添加到App.xaml
。it
App.xaml(v2.0.0及更高版本)io
<Application x:Class="WpfApplication.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.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" /> <!-- Accent and AppTheme setting --> <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
App.xaml(v1.6.5和更低版本)class
<Application x:Class="WpfApplication.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.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> </Application>