Skip to content

FileSavePicker: Cannot set default extension when defining FileTypeChoices #5975

@d2phap

Description

@d2phap

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions