FileSavePicker.FileTypeChoices 属性

定义

获取用户可以选择分配给文件的有效文件类型的集合。

public:
 property IMap<Platform::String ^, IVector<Platform::String ^> ^> ^ FileTypeChoices { IMap<Platform::String ^, IVector<Platform::String ^> ^> ^ get(); };
IMap<winrt::hstring, IVector<winrt::hstring> const&> FileTypeChoices();
public IDictionary<string,IList<string>> FileTypeChoices { get; }
var iMap = fileSavePicker.fileTypeChoices;
Public ReadOnly Property FileTypeChoices As IDictionary(Of String, IList(Of String))

属性值

IMap<String,IVector<String>>

IDictionary<String,IList<String>>

IMap<Platform::String,IVector<Platform::String>>

IMap<winrt::hstring,IVector<winrt::hstring>>

FilePickerFileTypesOrderedMap 对象,该对象包含用户可用于保存文件的有效文件类型 (扩展名) 集合。 此集合中的每个元素都将显示名称映射到相应的文件扩展名集合。 键是单个字符串,该值是表示一个或多个扩展选项的字符串的列表/矢量。

示例

文件选取器示例演示如何添加具有显示名称的文件类型选项。

FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
// Dropdown of file types the user can save the file as
savePicker.FileTypeChoices.Add("Plain Text", new List<string>() { ".txt" });
// Default file name if the user does not type one in or select a file to replace
savePicker.SuggestedFileName = "New Document";
auto plainTextExtensions{ winrt::single_threaded_vector<winrt::hstring>() };
plainTextExtensions.Append(L".txt");

savePicker.FileTypeChoices().Insert(L"Plain Text", plainTextExtensions);
savePicker.SuggestedFileName(L"New Document");

如果将多个 FileTypeChoices 添加到 FileSavePicker,则添加的第一个是默认文件类型。 当用户打开文件选取器时,将选择此默认值。 如果用户不更改文件选取器中的文件类型,则使用默认文件类型。 在此示例中,根据所选单选按钮添加 FileTypeChoices 条目:

if (radioButtonRichText.IsChecked)
{
    savePicker.FileTypeChoices.Add("Rich text", new List<string>() { ".rtf" });
    savePicker.FileTypeChoices.Add("Word document", new List<string>() { ".docx" });
    savePicker.FileTypeChoices.Add("Plain text", new List<string>() { ".txt" });
}
else if (radioButtonWordDoc.IsChecked)
{
    savePicker.FileTypeChoices.Add("Word document", new List<string>() { ".docx" });
    savePicker.FileTypeChoices.Add("Plain text", new List<string>() { ".txt" });
    savePicker.FileTypeChoices.Add("Rich text", new List<string>() { ".rtf" });
}
else // default to plain text file type
{
    savePicker.FileTypeChoices.Add("Plain text", new List<string>() { ".txt" });
    savePicker.FileTypeChoices.Add("Rich text", new List<string>() { ".rtf" });
    savePicker.FileTypeChoices.Add("Word document", new List<string>() { ".docx" });
}

注解

某些应用不需要了解文件格式即可对其进行处理,例如云存储提供商。 因此, FileOpenPicker.FileTypeFilter 集合支持使用文件通配符“*”。 但是,编写文件需要了解其格式。 因此,FileSavePicker.FileTypeChoices 不支持通配符。

作为文件类型分类的一个显示名称可能有多个支持它的文件类型。 例如,可以使用“.htm”或“.html”扩展名保存“HTML 页面”的显示名称。 正因如此 ,FilePickerFileTypesOrderedMap 中每个条目的值都是字符串向量) (有序列表,在 UI 中按向量中放置扩展的顺序显示。

适用于

另请参阅