FolderPicker

Modal dialog for browsing and selecting a folder.

Overview

FolderPicker extends Window and presents a modal dialog for browsing the filesystem and selecting a directory. Unlike FilePicker, only directories are displayed in the listing. Use Up/Down to navigate, Enter to descend into a directory, Space to select the currently highlighted directory, Backspace to navigate to the parent directory, and Escape to cancel without selecting. The control supports an IFileSystem abstraction for testing and virtualized file sources.

Basic Example

<FolderPicker Title="Select Folder"
              InitialDirectory="/home/user" />

Properties

PropertyTypeDefaultDescription
InitialDirectorystringCurrent directoryThe directory to display when the picker opens.
SelectedPathstring?nullThe full path of the selected folder after confirmation, or null if cancelled.
Titlestring"Select Folder"The title displayed in the dialog header.

Static API

// Show the folder picker and await the result
string? selectedFolder = await FolderPicker.ShowAsync(
    initialDirectory: "/home/user/projects",
    fileSystem: null  // uses real filesystem by default
);

if (selectedFolder is not null)
{
    Console.WriteLine($"Selected: {selectedFolder}");
}

The ShowAsync method creates a FolderPicker window, displays it modally, and returns the SelectedPath once the user confirms or null if cancelled. Pass a custom IFileSystem implementation for unit testing.

Examples

Simple Folder Selection

<FolderPicker Title="Choose Output Directory"
              InitialDirectory="/home/user/projects" />

Using ShowAsync in Code-Behind

private async Task OnSelectFolderClicked()
{
    var folder = await FolderPicker.ShowAsync(
        initialDirectory: Environment.GetFolderPath(
            Environment.SpecialFolder.MyDocuments)
    );

    if (folder is not null)
    {
        ViewModel.OutputDirectory = folder;
    }
}

With Custom IFileSystem for Testing

var mockFs = new MockFileSystem(new Dictionary<string, string[]>
{
    ["/root"] = ["docs", "src", "tests"],
    ["/root/src"] = ["app", "lib"]
});

var folder = await FolderPicker.ShowAsync(
    initialDirectory: "/root",
    fileSystem: mockFs
);

Keyboard Shortcuts

KeyAction
Up ArrowMove selection to the previous directory.
Down ArrowMove selection to the next directory.
EnterNavigate into the selected directory.
SpaceSelect the currently highlighted directory and close the dialog.
BackspaceNavigate to the parent directory (or delete last character in search mode).
EscapeExit search mode, or cancel the dialog and return null.
/Activate fuzzy search — type to filter directories in real-time.
ClickSelect the clicked directory entry.
Double-clickNavigate into the clicked directory.
Scroll wheelMove selection up or down.

Key Concepts