FilePicker

Modal dialog for browsing and selecting files from the filesystem.

Overview

FilePicker extends Window and presents a modal dialog for browsing the filesystem and selecting a file. Directories are displayed with a folder icon and files are listed below them. Use Up/Down to navigate the list, Enter to open a directory or select a file, Backspace to navigate to the parent directory, and Escape to cancel without selecting. An optional Filter property restricts the visible files (e.g., "*.txt"). The control supports an IFileSystem abstraction for testing and virtualized file sources.

Basic Example

<FilePicker Title="Select File"
            InitialDirectory="/home/user/documents"
            Filter="*.txt" />

Properties

PropertyTypeDefaultDescription
InitialDirectorystringCurrent directoryThe directory to display when the picker opens.
SelectedPathstring?nullThe full path of the selected file after confirmation, or null if cancelled.
Filterstring?nullGlob pattern to filter visible files (e.g., "*.txt", "*.cs"). Directories are always shown.
Titlestring"Select File"The title displayed in the dialog header.

Static API

// Show the file picker and await the result
string? selectedFile = await FilePicker.ShowAsync(
    initialDirectory: "/home/user/documents",
    filter: "*.txt",
    fileSystem: null  // uses real filesystem by default
);

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

The ShowAsync method creates a FilePicker 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

Unfiltered File Browser

<FilePicker Title="Open File"
            InitialDirectory="/home/user" />

Filtered by Extension

<FilePicker Title="Select Image"
            InitialDirectory="/home/user/pictures"
            Filter="*.png" />

Using ShowAsync in Code-Behind

private async Task OnOpenFileClicked()
{
    var path = await FilePicker.ShowAsync(
        initialDirectory: Environment.GetFolderPath(
            Environment.SpecialFolder.MyDocuments),
        filter: "*.cs"
    );

    if (path is not null)
    {
        ViewModel.FilePath = path;
    }
}

Keyboard Shortcuts

KeyAction
Up ArrowMove selection to the previous entry.
Down ArrowMove selection to the next entry.
EnterOpen the selected directory, or select the highlighted file 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 entries in real-time. Matches characters in order (not necessarily contiguous). Results are ranked by consecutive matches and word-boundary hits.
ClickSelect the clicked entry.
Double-clickOpen the clicked directory, or select the clicked file.
Scroll wheelMove selection up or down.

Key Concepts