FileSavePicker: Cannot set default extension when defining FileTypeChoices
Describe the bug
The default extension is always the first item in FileTypeChoices. Also, FileTypeChoices is always sorted, ignoring the original order!
var saveDialog = new FileSavePicker(AppWindow.Id)
{
DefaultFileExtension = ".xml",
};
saveDialog.FileTypeChoices.TryAdd("TXT", [".txt"]);
saveDialog.FileTypeChoices.TryAdd("JSON", [".json"]);
saveDialog.FileTypeChoices.TryAdd("XML", [".xml"]);
var picker = await saveDialog.PickSaveFileAsync();
Steps to reproduce the bug
Can reproduce with WinUI 3 Gallery:
Expected behavior
The selected extension of "Save as File" dropdown must match in this order:
- The extension from
SuggestedFileName, if it's defined in theFileTypeChoices - The
DefaultFileExtensionif it's defined in theFileTypeChoices.
See MS Paint:
Screenshots
NuGet package version
Windows App SDK 1.8.2: 1.8.251003001
Packaging type
Unpackaged
Windows version
Windows 11 version 24H2 LTSC (26100, June Update)
IDE
Other, Visual Studio 2022
Additional context
No response
Fixed in https://github.com/microsoft/WindowsAppSDK/pull/5948
Fixed in #5948
Correct me if I'm wrong. I think the PR only fixes the order of FileTypeChoices, not the default extension DefaultFileExtension which is different issue
@d2phap sorry i dont know enough, ask from PR creator
@d2phap Once that linked fix (#5948) is released (sounds like 1.8.4), you could probably workaround this issue, by placing your default choice first in the list of FileTypeChoices. But looks like a better fix (#6052) is on the way too.
-- I do not work for MS and I am not affliniated with WinAppSDK in any way.
Thanks @Marv51! Looking forward to the new version!