It's easy to use metro style in WPF, you can draw it yourself.
But in order to save time, ha, today we recommend a foreign Metro style control library.
This article only plays the role, has the interest or the recommendation everybody official Officer Net, Thanks, the website address I will send at the bottom.
Achieve results
In fact, the following is just a simple setup of the form, as well as put some simple buttons, this is the example of the sample program, in fact, there are a lot of fun style, including animation effects.
Installing Mahapps.metro
It is still recommended to use NuGet for installation, as shown in.
Then search for Mahapps.metro in NuGet and install it as shown in.
The installation has been completed in our references.
Achieve Metro Style Trilogy
1. First introduce resources to App.xaml
- <application x:class="Metrowpf.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>
- <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>
- </Application.Resources>
- </Application>
After introduction, almost all of our controls have the Metro style.
2. Replace the form with Metro style
The following xmlns references are made in a XAML-like body.
- xmlns:controls="Clr-namespace:mahapps.metro.controls;assembly=mahapps.metro"
Then replace the window tag with the following label
- <controls:metrowindow ...
It's OK.
Look at the XAML complete code for my form, I added three controls to do the example, as shown below.
- <controls:metrowindow x:class="Metrowpf.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"
- Glowbrush="{DynamicResource Accentcolorbrush}"
- Title="MainWindow" Height="=" Width="525">
- <controls:MetroWindow.RightWindowCommands>
- <controls:WindowCommands>
- <button Content="Settings" />
- <button Content="Settings" />
- </controls:WindowCommands>
- </controls:MetroWindow.RightWindowCommands>
- <Grid>
- <StackPanel>
- <label Margin=">www.wxzzz.com</Label>
- <textbox Margin="40,10,40,10"></TextBox>
- <Button>Metro Style Button</Button>
- </StackPanel>
- </Grid>
- </controls:MetroWindow>
3. Last step modify inheritance in form CS code
- Reference
- Using Mahapps. Metro. Controls;
- namespace metrowpf
- {
- // <summary>
- /// MainWindow.xaml's interactive logic
- // </summary>
- public partial class MainWindow : metrowindow
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- }
- }
Now that our example is complete, let's take a look at the official form example! In fact, are very simple settings, very useful.
This article sample source code download: METROWPF
Official Example Address: http://mahapps.com/guides/quick-start.html
Official Control Example Address: http://mahapps.com/controls/
Mahapps.metro Project Source: Https://github.com/MahApps/MahApps.Metro
WPF uses the Mahapps.metro UI library