zoukankan      html  css  js  c++  java
  • 项目笔记---WPF之Metro风格UI

    写在前面

      作为新年开篇的文章,当然要选择比较“Cool”的东西来分享,这自然落到了WPF身上,WPF技术自身可塑性非常强,其强大的绘图技术以及XAML技术比WinForm而言有本质的飞跃。

      切入正题,本文来自于一个项目的Demo演示版,当然为了做到“Cool”我选择了WPF作为项目的概念版进行演示,所用到包括大名鼎鼎的MahApps.Metro以及AvalonDock等开源框架完美发挥WPF的优势,本文不会很深入的讲解每个技术的详细功能,而是结合项目Demo进行一个“组合式”框架的介绍,希望各位读者喜欢,如果觉得值得还不错的话,请点击“推荐一下”。

    先睹为快:

     

    1. 使用MahApps.Metro搭建框架

    1.1 快速应用最精简的项目

    首先要增加对MahApps.Metro和MahApps.Metro.Resources的引用;

    其次,窗体要继承 Metro.MetroWindow (Controls:MetroWindow x:Class="TestDemo.MainWindow")。

    这样,窗体有了基本的样式风格和主题颜色,另外MahApps.Metro增强了标题栏,可定制“左侧功能区域”和“右侧功能区域”,例如

    "Setting"和“About”按钮功能以及左侧GitHub图标功能,扩展了界面上可编辑元素,直接在MetroWindow.LeftWindowCommand中增加内容即可:

        <!--Left Window Commands-->
        <Controls:MetroWindow.LeftWindowCommands>
            <Controls:WindowCommands>
                <Button Click="LaunchMahAppsOnGitHub"
                        ToolTip="MahApps.Metro on GitHub">
                    <Rectangle Width="22"
                               Height="22"
                               Fill="{Binding RelativeSource={RelativeSource AncestorType=Button}, Path=Foreground}">
                        <Rectangle.OpacityMask>
                            <VisualBrush Stretch="Uniform"
                                         Visual="{StaticResource appbar_github}" />
                        </Rectangle.OpacityMask>
                    </Rectangle>
                </Button>
            </Controls:WindowCommands>
        </Controls:MetroWindow.LeftWindowCommands>
        <!--Right Window Commands-->
        <Controls:MetroWindow.RightWindowCommands>
            <Controls:WindowCommands>
                <Button Click="MainWindow_Setting"
                        ToolTip="Software Configuration"
                        Content="Setting" />
                <Button Click="MainWindow_About"
                        ToolTip="Software Information"
                        Content="About" />
            </Controls:WindowCommands>
        </Controls:MetroWindow.RightWindowCommands>
    View Code

    至此,基本框架已经形成,接下来让我们了解MahApps提供的Metro风格的控件吧。

    1.2 增加Metro风格的控件

    这里最好的参考是官方的Demo,需要使用控件时只需要对应的拷贝一些“代码”即可。直接上图:

     

    2. 使用AvalonDock

    2.1 AvalonDock2.0的问题

    在这篇文章之前,本人使用的是2.0版本,官网提供了最新的下载,可是在使用的过程中有一个非常严重的问题:整合在MahApps框架中,AvalonDock的AutoHide控件持续“透明”,这一BUG在2.0当中存在。

    设置AllowsTransparency =“FALSE"也不能解决此问题,最终还原为1.3稳定版。

    2.2 如何定制布局

    最好的参考还是官方文档:http://avalondock.codeplex.com/wikipage?title=GettingStarted&referringTitle=Documentation 这里还是1.3版本,官网2.0版本文档还在建设中。。。总感觉作者已经不在维护此项目了,着实令人寒心。

    3. 结语及引用

    Demo点此下载

    有任何问题欢迎大家提问,很多细节之处没有写出来,Demo中会有体现。

  • 相关阅读:
    您还在用下一步下一步的方式安装SQLSERVER和SQLSERVER补丁吗?
    SQLSERVER误删除了Windows登录用户验证方式使用Windows身份验证的解决方法
    批量解密SQLSERVER数据库中的各种对象的工具dbForge SQL Decryptor
    SQLSERVER将数据移到另一个文件组之后清空文件组并删除文件组
    SQLSERVER群集故障转移笔记
    兼容,原来在这里就已经開始--------Day34
    Objective-C的对象模型和runtime机制
    CF B. Kolya and Tandem Repeat
    循环队列的实现
    LintCode 子树
  • 原文地址:https://www.cnblogs.com/cuiyansong/p/4202342.html
Copyright © 2011-2022 走看看