MahApps.Metro使用
MahApps.Metro使用
下载MahApps.Metro
PM> Install-Package MahApps.Metro
MainWindow.xaml中添加
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
然后将Window标签替换为如下标签
<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">
</Controls:MetroWindow>
MainWindow.xaml.cs添加
using MahApps.Metro.Controls;
namespace WpfApplication
{
public partial class MainWindow : MetroWindow
{
public MainWindow()
{
InitializeComponent();
}
}
}
使用内置的样式App.xaml
<Application.Resources>
<ResourceDictionary.MergedDictionaries>
</ResourceDictionary.MergedDictionaries>
</Application.Resources>
修改标题栏
可以添加自己的控制 LeftWindowsCommands 或 RightWindowsCommands
内添加:
Controls:MetroWindow.RightWindowCommands
Controls:WindowCommands
</Controls:WindowCommands>
</Controls:MetroWindow.RightWindowCommands>
显示图标需要加载MahApps.Metro.Resources资源
MahApps.Metro.Resources使用
下载MahApps.Metro.Resources
PM> Install-Package MahApps.Metro.Resources
MainWindow.xaml文件中添加
<Window.Resources>
<ResourceDictionary.MergedDictionaries>
</ResourceDictionary.MergedDictionaries>
</Window.Resources>
如何改变目前的主题 Styles
You can choose between these available accents:
“Red”, “Green”, “Blue”, “Purple”, “Orange”, “Lime”, “Emerald”, “Teal”, “Cyan”, “Cobalt”, “Indigo”, “Violet”, “Pink”, “Magenta”, “Crimson”, “Amber”, “Yellow”, “Brown”, “Olive”, “Steel”, “Mauve”, “Taupe”, “Sienna”
and these themes:
“BaseLight”, “BaseDark”
通过App.xaml,直接修改其中对应的部分
<Application.Resources>
<ResourceDictionary.MergedDictionaries>
</ResourceDictionary.MergedDictionaries>
</Application.Resources>
通过ThemeManager
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
// get the current app style (theme and accent) from the application
// you can then use the current theme and custom accent instead set a new theme
Tuple<AppTheme, Accent> appStyle = ThemeManager.DetectAppStyle(Application.Current);
// now set the Green accent and dark theme
ThemeManager.ChangeAppStyle(Application.Current,
ThemeManager.GetAccent("Green"),
ThemeManager.GetAppTheme("BaseDark")); // or appStyle.Item1
base.OnStartup(e);
}
}
在主窗口中修改
MainWindow.xaml文件
Controls:MetroWindow.Resources
<ResourceDictionary.MergedDictionaries>
</ResourceDictionary.MergedDictionaries>
</Controls:MetroWindow.Resources>
主类MetroWindow中
public partial class AccentStyleWindow : MetroWindow
{
public void ChangeAppStyle()
{
// set the Red accent and dark theme only to the current window
ThemeManager.ChangeAppStyle(this,
ThemeManager.GetAccent("Red"),
ThemeManager.GetAppTheme("BaseDark"));
}
}
还可以自定义主题
参考:
- http://rehansaeed.com/wpf-metro-part1-modern-ui-for-wpf/
- https://github.com/MahApps/MahApps.Metro
- http://mahapps.com/guides/quick-start.html
- http://www.wxzzz.com/1202.html
- http://mahapps.com/guides/icons-and-resources.html
- http://mahapps.com/guides/styles.html
- http://mahapps.com/controls/
- https://github.com/MahApps/MahApps.Metro.IconPacks
- http://fontawesome.io/icons/
- https://materialdesignicons.com/



浙公网安备 33010602011771号