FileOpenPickerUI 类

定义

如果你的应用提供具有文件打开选取器合约的文件,则用于与文件选取器交互。

public ref class FileOpenPickerUI sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class FileOpenPickerUI final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class FileOpenPickerUI
Public NotInheritable Class FileOpenPickerUI
继承
Object Platform::Object IInspectable FileOpenPickerUI
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

文件选取器提供程序示例演示如何响应 FileOpenPicker 激活事件。

// File open picker activated event handler
protected override void OnFileOpenPickerActivated(FileOpenPickerActivatedEventArgs args)
{
    var FileOpenPickerPage = new SDKTemplate.FileOpenPickerPage();
    FileOpenPickerPage.Activate(args);
}

// Overloaded method to respond to fileOpenPicker events
public void Activate(FileOpenPickerActivatedEventArgs args)
{
    // Perform tasks to prepare your app to display its file picker page

    // Get file picker UI
    fileOpenPickerUI = args.FileOpenPickerUI;

    Window.Current.Content = this;
    this.OnNavigatedTo(null);
    Window.Current.Activate();
}

对于 C#, args 包含 FileOpenPickerActivatedEventArgs 对象。 此外, OnFileOpenPickerActivated 位于 App.xaml.cs 文件中, Activate 方法位于 文件选取器提供程序示例的 FileOpenPickerPage.xaml.cs 文件中。

注解

如果你的应用参与文件打开选取器合约,则可以在处理 FileOpenPicker 激活事件时使用 FileOpenPickerUI 属性检索此对象。

使用 Windows.ApplicationModel.Activation.FileOpenPickerActivatedEventArgs.FileOpenPickerUI 属性访问 FileOpenPickerUI。

阅读使用选取器在 打开文件和文件夹中提供文件的 UX 指南,了解如何在用户通过文件选取器访问文件时创建良好的体验。

属性

AllowedFileTypes

获取用户可以选择的文件类型 (扩展名) 的列表。

SelectionMode

获取一个枚举值,该值指示文件选取器当前是否将选择限制为单个文件,或者是否可以选择多个文件。

SettingsIdentifier

获取文件选取器当前上下文的标识符。

Title

获取或设置在文件选取器 UI 中显示的标题,该标题标识文件选取器向用户显示的位置。

方法

AddFile(String, IStorageFile)

将指定的文件添加到用户选择的文件列表中。

CanAddFile(IStorageFile)

指示是否可以将指定的文件添加到用户选择的文件列表中。

ContainsFile(String)

确定指定的文件是否位于用户选择的文件列表中。

RemoveFile(String)

从用户选择的文件列表中删除指定的文件。

事件

Closing

当用户关闭文件选取器时触发。

FileRemoved

注意

FileRemoved 事件已弃用,不应使用。

如果用户从用户选择的文件列表中删除文件,如果该文件是由提供文件的应用添加的,则触发。

适用于

另请参阅