WPF uses the Mahapps.metro UI library

Source: Internet
Author: User

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

  1. <application x:class="Metrowpf.app"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"
  4. StartupUri="MainWindow.xaml">
  5. <Application.Resources>
  6. <ResourceDictionary>
  7. <ResourceDictionary.MergedDictionaries>
  8. <resourcedictionary Source="pack://application:,,,/mahapps.metro;component/styles/ Controls.xaml " />
  9. <resourcedictionary Source="pack://application:,,,/mahapps.metro;component/styles/ Fonts.xaml " />
  10. <resourcedictionary Source="pack://application:,,,/mahapps.metro;component/styles/ Colors.xaml " />
  11. <resourcedictionary Source="pack://application:,,,/mahapps.metro;component/styles/ Accents/blue.xaml " />
  12. <resourcedictionary Source="pack://application:,,,/mahapps.metro;component/styles/ Accents/baselight.xaml " />
  13. </ResourceDictionary.MergedDictionaries>
  14. </ResourceDictionary>
  15. </Application.Resources>
  16. </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.

    1. xmlns:controls="Clr-namespace:mahapps.metro.controls;assembly=mahapps.metro"

Then replace the window tag with the following label

    1. <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.

  1. <controls:metrowindow x:class="Metrowpf.mainwindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:controls="Clr-namespace:mahapps.metro.controls;assembly=mahapps.metro"
  5. Glowbrush="{DynamicResource Accentcolorbrush}"
  6. Title="MainWindow" Height="=" Width="525">
  7. <controls:MetroWindow.RightWindowCommands>
  8. <controls:WindowCommands>
  9. <button Content="Settings" />
  10. <button Content="Settings" />
  11. </controls:WindowCommands>
  12. </controls:MetroWindow.RightWindowCommands>
  13. <Grid>
  14. <StackPanel>
  15. <label Margin=">www.wxzzz.com</Label>
  16. <textbox Margin="40,10,40,10"></TextBox>
  17. <Button>Metro Style Button</Button>
  18. </StackPanel>
  19. </Grid>
  20. </controls:MetroWindow>

3. Last step modify inheritance in form CS code

  1. Reference
  2. Using Mahapps. Metro. Controls;
  3. namespace metrowpf
  4. {
  5. // <summary>
  6. /// MainWindow.xaml's interactive logic
  7. // </summary>
  8. public partial class MainWindow : metrowindow
  9. {
  10. public MainWindow()
  11. {
  12. InitializeComponent();
  13. }
  14. }
  15. }

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

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.