首页 > 其他分享 >WPF-UI框架MahApps.Metro使用教程

WPF-UI框架MahApps.Metro使用教程

时间:2022-10-05 15:55:14浏览次数:58  
标签:MahApps Metro -- xaml Window UI MainWindow

一,MahApps.Metro安装

1,项目中引用“MahApps.Metro.dll”【失败】

我是在网上下载了一个dll,不知道是不是版本问题,使用时一直报错

2,在NuGet中安装最新版本的dll

右击项目-->选择 “管理Nuget程序包”-->搜索“MahApps.Metro”

二,MahApps.Metro安装使用

1,在xaml窗体引用命名空间

xmlns:metro="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"

2,对Window标签进行替换

<metro:MetroWindow> </metro:MetroWindow>

 

 

3,对xaml.cs中继承的Window进行替换

    //public partial class MainWindow : Window
    public partial class MainWindow : MetroWindow
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }

 

4,在xaml.cs中引用命名空间

using MahApps.Metro.Controls;

5,在App.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/Themes/Light.Blue.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>

  

三,使用:给主题换颜色

<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />

把Blue改成Red ,主题就变红色啦。

标签:MahApps,Metro,--,xaml,Window,UI,MainWindow
From: https://www.cnblogs.com/baozi789654/p/16755696.html

相关文章