Skip to main content

File picker

A file browser that ships with the framework: a places sidebar on the left, a Name / Date Modified / Size / Kind table on the right, a toolbar with history arrows and a filter field, and a status row with the item count and a key legend.

It is registered by AddArlecchino under the route Routes.FilePicker, so nothing has to be wired up.

Asking for a path

private readonly ArlecchinoState _state;

_state.FilePicker = new FilePickerRequest(
Title: "Pick a folder",
PickFolder: true,
InitialPath: Environment.CurrentDirectory,
ReturnView: ViewKind.Default,
OnPicked: path => _state.Output = $"picked: {path}");

return Routes.FilePicker;

Fill ArlecchinoState.FilePicker, then navigate to Routes.FilePicker — the view reads the request in its constructor. Navigating there without a request opens a folder picker rooted at the drive list that returns to ViewRoute.None.

MemberMeaning
TitleShown in the toolbar
PickFoldertrue picks directories, false picks files
InitialPathWhere browsing starts: a folder is opened, a file is opened in the folder that holds it and starts under the cursor, and a path that no longer exists starts at the drive list
ReturnViewRoute navigated to after a pick or a cancel
OnPickedCalled with the chosen path before returning
PlacesExtra sidebar entries, listed above the standard favorites
FileFilterPredicate over the full path; files that fail it are not listed
_state.FilePicker = new FilePickerRequest(
"Pick a save",
PickFolder: false,
start,
ViewKind.Default,
Load)
{
Places = [new FilePickerPlace("Game saves", savesPath, "▪")],
FileFilter = static path => path.EndsWith(".sav", StringComparison.OrdinalIgnoreCase),
};

The request is cleared on pick and on cancel, and ArlecchinoState.PickerLastFolder is set to the folder the picker ended in — pass it as the next InitialPath to resume where the user left off.

Above the standard entries come the request's own Places. Then Favorites — Desktop, Documents, Downloads, Pictures, Music, Videos, each skipped when the folder does not exist — and Locations: the home folder, This computer, and every ready drive. Section headers are not selectable.

Keys

KeyIn the listIn the sidebar
Move the selectionMove between places
PgUp PgDn Home EndJump ten rows / to the ends
Enter the selected folderFocus the list
Go to the parent folder, or focus the sidebar when already at the drive list
EnterOpen a folder; pick a file when picking filesGo to the place and focus the list
Ctrl+EnterPick the current folder when picking folders
TabSwitch panesSwitch panes
BackspaceShorten the filter, or go up when it is empty
any characterAppends to the filter
EscCancel and return to ReturnViewCancel

Typed characters go through KeyText, so filtering works on a non-latin layout — see Keyboard.

Text

Every label, column header, size, date and kind string is a delegate on ArlecchinoStrings.FilePicker, including the defaults that format 12.3 MB, Today at 9:41 and ZIP archive. See Localization.