作为新年开篇的文章,当然要选择比较“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>