深入探讨WPF对话框使用技巧

WPF开发工具的应用帮助我们实现了许多功能需求。那么如何正确的应用WPF中各种控件,是掌握这一工具的真理所在。在WPF中,系统定义的WPF对话框(Dialog)有三种:#t#

成都创新互联公司专业为企业提供太湖网站建设、太湖做网站、太湖网站设计、太湖网站制作等企业网站建设、网页设计与制作、太湖企业网站模板建站服务,10余年太湖做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

(1)Microsoft.Win32.OpenFileDialog

(2)Microsoft.Win32.SaveFileDialog

(3)System.Windows.Controls.PrintDialog

先看看前面两种WPF对话框的层次继承关系:

System.Object

Microsoft.Win32.CommonDialog

Microsoft.Win32.FileDialog

Microsoft.Win32.OpenFileDialog

Microsoft.Win32.SaveFileDialog

我们看到,这两种对话框均位于Microsoft.Win32命名空间中,它们均继承自Microsoft.Win32.FileDialog。

(1)OpenFileDialog:
OpenFileDialog有一种公共事件:FileOk(当用户选择文件名,点击打开按钮时发生)

OpenFileDialog有以下几种公共方法:

OpenFile():打开单个文件

OpenFiles():打开多个文件

Reset():重置

ShowDialog():显示对话框

OpenFileDialog的公共属性有:
.AddExtension,
.CheckFileExists,
.CheckPathExists,
.DefaultExt,
.DereferenceLinks,
.FileName,
.FileNames,
.Filter,
.FilterIndex,
.InitialDirectory,
.Multiselect,
.ReadOnlyChecked,
.RestoreDirectory,
.SafeFileName,
.SafeFileNames,
.ShowReadOnly,
.Tag,
.Title,
.ValidateNames

其中,我们最常用的WPF对话框有: FileName, FileNames, Filter, FilterIndex, DefaultExt,InitialDirectory等。

(2) SaveFileDialog:

与OpenFileDialog类似,SaveFileDialog公共方法:
OpenFile()
Reset()
ShowDialog()

公共属性:
.AddExtension,
.CheckFileExists,
.CheckPathExists,
.CreatePrompt,
.DefaultExt,
.DereferenceLinks,
.FileName,
.FileNames,
.Filter,
.FilterIndex,
.InitialDirectory,
.OverwritePrompt,
.RestoreDirectory,
.SafeFileName,
.SafeFileNames,
.Tag,
.Title,
.ValidateNames

说明:在WPF中的Microsoft.Win32.OpenFileDialog,Microsoft.Win32.SaveFileDialog与在WinForm中的System.Windows.Forms.OpenFileDialog, System.Windows.Forms.SaveFileDialog用法上基本上一样,但前者由于WPF的限制,无法在Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE下使用。

再看看看PrintDialog:

(3)PrintDialog:

看看它的继承关系:
System.Object
System.Windows.Controls.PrintDialog

WPF对话框需要注意的是:不要将System.Windows.Controls.PrintDialog与System.Windows.Forms.PrintDialog混淆了,后者用于WinForm应用程序中。System.Windows.Controls.PrintDialog则用于Windows Presentation Foundation (WPF)应用程序中。

名称栏目:深入探讨WPF对话框使用技巧
文章起源:http://www.hantingmc.com/qtweb/news43/103643.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联