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 中。

適用於

另請參閱