WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

FileSavePicker: Cannot set default extension when defining FileTypeChoices

Open d2phap opened this issue 1 month ago • 5 comments

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:

Image

Expected behavior

The selected extension of "Save as File" dropdown must match in this order:

  1. The extension from SuggestedFileName, if it's defined in the FileTypeChoices
  2. The DefaultFileExtension if it's defined in the FileTypeChoices.

See MS Paint: Image

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

d2phap avatar Nov 04 '25 14:11 d2phap

Fixed in https://github.com/microsoft/WindowsAppSDK/pull/5948

ghost1372 avatar Nov 04 '25 15:11 ghost1372

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 avatar Nov 04 '25 15:11 d2phap

@d2phap sorry i dont know enough, ask from PR creator

ghost1372 avatar Nov 04 '25 17:11 ghost1372

@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.

Marv51 avatar Dec 04 '25 10:12 Marv51

Thanks @Marv51! Looking forward to the new version!

d2phap avatar Dec 05 '25 06:12 d2phap