简体   繁体   中英

UWP C# FileSavePicker -> DefaultFileExtension

How to set the DefaultExtension? In the following code, the first entry is, so gif displayed. DefaultExtension but png. What should I change to make it work?

Code snippet:

var savePicker = new FileSavePicker
{
     SuggestedStartLocation = PickerLocationId.PicturesLibrary,
     CommitButtonText = "Save",
     DefaultFileExtension = ".png",
     SettingsIdentifier = "fsp1",
     SuggestedFileName = "MyImage"
};
savePicker.FileTypeChoices.Add("Gif-Image", new List<string> { ".gif" });
savePicker.FileTypeChoices.Add("Jpeg-Image", new List<string> { ".jpg" });
savePicker.FileTypeChoices.Add("Png-Image", new List<string> { ".png" });
savePicker.FileTypeChoices.Add("Ico-File", new List<string> { ".ico" });
savePicker.FileTypeChoices.Add("Bmp-Image", new List<string> { ".bmp" });
StorageFile file = await savePicker.PickSaveFileAsync();

Thank you for reporting this issue, we've confirmed that this is a logged issue. As currently implemented the DefaultFileExtension provides no meaningful use.

What should I change to make it work?

If you want to make the default file extension to be .png, here is a workaround:

Move your code savePicker.FileTypeChoices.Add("Png-Image", new List<string> { ".png" }); before savePicker.FileTypeChoices.Add("Gif-Image", new List<string> { ".gif" }); . The first extension will be the default one in the list of FileTypeChoices .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM