【mahapps.metro】WPF“关于”窗体
来源:互联网 发布:冰雪奇缘音乐分析知乎 编辑:程序博客网 时间:2024/06/05 03:05
写在前面的话
无论什么系统,都会有一个“关于”页面,用来显示系统、开发人员以及版权等信息。在Windows Form中,VS2013已经给出了现成的“关于”框模板,但是不知道为什么WPF中并没有给出,不过我们可以参照Windows Form的“关于”框来打造自己的。
Windows Form
- 在建立窗体之前,先来完善自己系统的程序集信息
- 打开自己项目的“属性“,选择应用程序中的程序集信息
- 填写自己的程序集信息
- 信息完成后,来设计自己的窗体,右击自己的项目,选择”添加““新建项”
- 窗体如下所示:
- 到这里工作就完成了,运行既可。
WPF
- 完善程序集信息参照前面的Windows Form,现在需要做的是设计一个WPF窗体
- 推荐大家使用Blend,首先完成页面布局,然后添加我们所需要的lable,button等控件,左面可以放自己系统的Logo,右面是一些系统信息,自由发挥。
- 页面设计好之后,还需要后台代码来获取程序集信息,复制Windows Form的后台代码就可以,这里把代码贴出来,方便大家参考。
- 注意:需要使用反射
using System.Reflection;
- 代码如下:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using MahApps.Metro.Controls;using System.Reflection;namespace JFUI{ /// <summary> /// frmAbout.xaml 的交互逻辑 /// </summary> public partial class frmAbout : MetroWindow { private static frmAbout instance; public frmAbout() { InitializeComponent(); this.Title = String.Format("关于 {0}", AssemblyTitle); this.lblProductName.Content = AssemblyProduct; this.lblVersion.Content = String.Format("版本 {0}", AssemblyVersion); this.lblCopyright.Content = AssemblyCopyright; this.lblCompanyName.Content = AssemblyCompany; this.txtDetailDescription.Text = AssemblyDescription; btnOK.Focus(); } public static frmAbout GetInstance() { if (instance == null) { instance = new frmAbout(); } return instance; } private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { instance = null; } private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { this.Title = String.Format("关于 {0}", AssemblyTitle); this.lblProductName.Content = AssemblyProduct; this.lblVersion.Content = String.Format("版本 {0}", AssemblyVersion); this.lblCopyright.Content = AssemblyCopyright; this.lblCompanyName.Content = AssemblyCompany; this.txtDetailDescription.Text = AssemblyDescription; } #region 程序集特性访问器 public string AssemblyTitle { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false); if (attributes.Length > 0) { AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0]; if (titleAttribute.Title != "") { return titleAttribute.Title; } } return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase); } } public string AssemblyVersion { get { return Assembly.GetExecutingAssembly().GetName().Version.ToString(); } } public string AssemblyDescription { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyDescriptionAttribute)attributes[0]).Description; } } public string AssemblyProduct { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyProductAttribute)attributes[0]).Product; } } public string AssemblyCopyright { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; } } public string AssemblyCompany { get { object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false); if (attributes.Length == 0) { return ""; } return ((AssemblyCompanyAttribute)attributes[0]).Company; } } #endregion private void btnOK_Click(object sender, RoutedEventArgs e) { this.Close(); } }}
- 运行后:
1 0
- 【mahapps.metro】WPF“关于”窗体
- 【mahapps.metro】使用如何添加WPF窗体图标
- 【mahapps.metro】WPF窗体Dialogs(对话框)的使用
- 【mahapps.metro】WPF窗体关闭,提示用户是否退出对话框
- 【mahapps.metro】如何快速让WPF窗体具有Metro扁平化风格
- WPF 使用MahApps.Metro UI库
- WPF metro扁平化UI控件库:MahApps.Metro
- WPF清爽酷炫的界面Mahapps.metro
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- WPF 自定义Metro Style窗体
- 欢迎使用CSDN-markdown编辑器
- LoadRunner如何测试mysql语句
- Eclipse 中关联JDK源代码
- oracle 查询当前占用cpu及时间最长的sql语句
- Theme.AppCompat.Light无法找到问题
- 【mahapps.metro】WPF“关于”窗体
- 高仿今日头条(1)
- JVM垃圾回收--年轻代、年老点和持久代
- iOS开发实践之GET和POST请求
- 在PHP语言中使用JSON
- iptables学习笔记1
- C语言实现非递归的比较两个二叉树是否同构
- Xcode中iOS工程的Group结构与文件系统同步-SyncXcodeFolder
- 设置不同的android:inputTye属性时,如果修改EditText hint 的字体