当前位置: 移动技术网 > IT编程>开发语言>.net > wpf开源控件MahApps.Metro

wpf开源控件MahApps.Metro

2020年04月23日  | 移动技术网IT编程  | 我要评论

请与废柴的我谈恋爱10,uutxt.org,预告电影

wpf开源控件mahapps.metro

安装

您可以通过nuget gui(右键单击您的项目,单击manage nuget packages,选择online并搜索mahapps.metro)或使用package manager控制台安装mahapps.metro。

pm> install-package mahapps.metro

或使用软件包管理器控制台:

pm> install-package mahapps.metro -pre

造型窗口

您可以使用两种方法使用mahapps.metro设置window的样式:

修改xaml文件

安装mahapps.metro之后:

  • 打开 mainwindow.xaml
  • 在打开的window标记内添加此属性。(这是您在xaml中引用其他名称空间的方式):
    xmlns:controls="clr-namespace:mahapps.metro.controls;assembly=mahapps.metro"

    xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
  • 标签更改为(请记住也要更改结束标签!)

您应该有类似以下内容(请勿复制和粘贴):

<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">

  <!-- your content -->

</controls:metrowindow>

修改codebehind文件

您还需要修改mainwindow.xaml.cs文件,以使其基类mainwindowmetrowindowxaml文件的类匹配。

// to access metrowindow, add the following reference
using mahapps.metro.controls;

namespace wpfapplication
{
  public partial class mainwindow : metrowindow
  {
    public mainwindow()
    {
      initializecomponent();
    }
  }
}

但是在大多数情况下,您可以删除基类(因为这是partialxaml应该处理的类):

namespace wpfapplication
{
  public partial class mainwindow
  {
    public mainwindow()
    {
      initializecomponent();
    }
  }
}

使用内置样式

mahapp.metro的所有资源都包含在单独的资源词典中。为了使大多数控件采用mahapps.metro主题,您需要将resourcedictionaries添加到app.xaml

app.xaml(v2.0.0及更高版本)

<application x:class="wpfapplication.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>
        <!-- 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" />
        <!-- accent and apptheme setting -->
        <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/themes/light.blue.xaml" />
      </resourcedictionary.mergeddictionaries>
    </resourcedictionary>
  </application.resources>
</application>

app.xaml(v1.6.5和更低版本)

<application x:class="wpfapplication.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>
        <!-- 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/blue.xaml" />
        <resourcedictionary source="pack://application:,,,/mahapps.metro;component/styles/accents/baselight.xaml" />
      </resourcedictionary.mergeddictionaries>
    </resourcedictionary>
  </application.resources>
</application>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网