MahApps.Metro是一款win10扁平化风格的开源控件库。
- 安装MahApps.Metro
项目右键,管理NuGet程序包,浏览,搜索MahApps.Metro,安装;
- 应用
App.xaml内容如下,Steel.xaml为默认主题颜色,可修改。
<Application x:Class="ProjectName.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:IPT2018"
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/Steel.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
MainWindow.xaml中MainWindow改为Controls:MetroWindow;
添加引用
xmlns:Controls="http://metro.mahapps.com/winfx/xaml/controls"
后台文件修改为 public partial class MainWindow;
- 修改主题
Accent newAccent = ThemeManager.GetAccent("Red");
AppTheme newTheme = ThemeManager.GetAppTheme("BaseDark");
ThemeManager.ChangeAppStyle(Application.Current, newAccent, newTheme);
- 对话框
private async void MainWindwo_Closing(object sender, CancelEventArgs e)
{
e.Cancel = true;
var mySettings = new MetroDialogSettings()
{
AffirmativeButtonText = "确定", // Confirm
NegativeButtonText = "关闭", // Close
AnimateShow = true,
AnimateHide = false
};
// Confirm to close; Sure to close ?
var result = await this.ShowMessageAsync("关闭确认", "确定关闭窗口吗?", MessageDialogStyle.AffirmativeAndNegative, mySettings);
if (result == MessageDialogResult.Affirmative)
{
System.Windows.Application.Current.Shutdown();
}
}