本文共 2754 字,大约阅读时间需要 9 分钟。
一、新建Wpf项目,需要添加引用
Install-Package WindowsAPICodePack-CoreInstall-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. |