C# Windows-API-Code-Pack文件选择对话框实例

一、新建Wpf项目,需要添加引用

Install-Package WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-Shell

二、选择文件对话框实例CommonOpenFileDialog

选择媒体文件

//指定视频文件夹选择视频文件
//系统文件夹可能会获取失败
//ShellContainer selFolder = KnownFolders.SampleMusic as ShellContainer;
CommonOpenFileDialog open = new CommonOpenFileDialog();
//open.InitialDirectoryShellContainer = selFolder;
open.EnsureReadOnly = true;
open.Filters.Add(new CommonFileDialogFilter("Mp4文件", "*.mp4"));
open.Filters.Add(new CommonFileDialogFilter("Wmv文件","*.wmv"));
open.Filters.Add(new CommonFileDialogFilter("Avi文件", "*.avi"));
open.Filters.Add(new CommonFileDialogFilter("Mp3文件", "*.mp3"));
if (open.ShowDialog() == CommonFileDialogResult.Ok)
{
    //指定媒体文件地址
    mediaElement.Source = new Uri(open.FileName,UriKind.Relative);
    playBtn.


三、Microsoft.WindowsAPICodePack.Dialogs Namespace部分类

Class Description
CommonFileDialog

Defines the abstract base class for the common file dialogs.

CommonFileDialogFilter

Stores the file extensions used when filtering files in File Open and File Save dialogs.

CommonFileDialogFilterCollection

Provides a strongly typed collection for file dialog filters.

CommonFileDialogFolderChangeEventArgs

Creates the event data associated with FolderChanging event.

CommonFileDialogStandardFilters

Defines the class of commonly used file filters.

CommonOpenFileDialog

Creates a Vista or Windows 7 Common File Dialog, allowing the user to select one or more files.

CommonSaveFileDialog

Creates a Vista or Windows 7 Common File Dialog, allowing the user to select the filename and location for a saved file.

DialogControl

Abstract base class for all dialog controls

DialogControlCollection<(Of<(<'T>)>)>

Strongly typed collection for dialog controls.

TaskDialog

Encapsulates a new-to-Vista Win32 TaskDialog window - a powerful successor to the MessageBox 

available in previous versions of Windows.

TaskDialogBar

Defines a common class for all task dialog bar controls, such as the progress and marquee bars.

TaskDialogButton

Implements a button that can be hosted in a task dialog.

TaskDialogButtonBase

Defines the abstract base class for task dialog buttons. 

Classes that inherit from this class will inherit the Text property defined in this class.

TaskDialogClosingEventArgs

Data associated with Closing event.

TaskDialogCommandLink

Represents a command-link.

TaskDialogControl

Declares the abstract base class for all custom task dialog controls.

TaskDialogHyperlinkClickedEventArgs

Defines event data associated with a HyperlinkClick event.

TaskDialogProgressBar

Provides a visual representation of the progress of a long running operation.

TaskDialogRadioButton

Defines a radio button that can be hosted in by a TaskDialog object.

TaskDialogTickEventArgs

The event data for a TaskDialogTick event.  




  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值