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

 

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

先睹为快:

 项目笔记---WPF之Metro风格UI

1. 使用MahApps.Metro搭建框架

1.1 快速应用最精简的项目

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

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

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

项目笔记---WPF之Metro风格UI

"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

相关文章:

  • 2022-12-23
  • 2021-09-13
  • 2022-02-06
  • 2021-08-07
  • 2022-01-08
  • 2022-01-27
猜你喜欢
  • 2021-12-26
  • 2021-11-04
  • 2021-07-04
  • 2022-12-23
  • 2021-10-18
  • 2022-12-23
相关资源
相似解决方案