A lazy-loading and better WinUI 3 TreeView custom control for navigating filesystem paths and virtual hierarchies such as ZIP archives, FTP listings, or any custom data source.
Filesystem view — all drives, expand any drive to lazy-load its subfolders
Hidden and system folders shown at 50% opacity
ZIP archive structure exposed as a navigable tree via VirtualTreeNodeProvider
- Lazy loading — children are fetched on demand when the user expands a node; no full scan at startup
- Filesystem provider — browses all drives or a specific root path; optional hidden and system folder display with automatic dimmed opacity
- Virtual provider — builds a navigable tree from any flat list of slash-separated paths (ZIP entries, FTP listings, database hierarchies…)
- Custom provider — implement
ITreeNodeProviderto connect any data source - Path reveal —
RevealPathAsync(path)programmatically expands and scrolls to any path - Reload —
ReloadAsync()refreshes the entire tree without disposing the control - Search / filter — built-in
AutoSuggestBoxwith real-time node filtering (virtual provider) or configurable behaviour - Custom icons — per-node icon, control-level
RootIcon/NodeIconoverride; accepts Segoe Fluent Icons glyph, PNG, or SVG - Tooltip — full path shown on hover for every node
- Hidden folder dimming — nodes with
IsHidden = trueare rendered at 50% opacity viaBoolToOpacityConverter - MIT licensed
| Requirement | Minimum version |
|---|---|
| .NET | 9.0 |
| Windows | 10 version 1809 (build 17763) |
| Windows App SDK | 1.8 |
| Target framework | net9.0-windows10.0.19041.0 |
dotnet add package BetterPathTreeview_WinUI3
Or search for BetterPathTreeview_WinUI3 in the Visual Studio NuGet Package Manager.
xmlns:ctrl="using:BetterPathTreeview.Control"// All drives
public FileSystemTreeNodeProvider FsProvider { get; } =
new FileSystemTreeNodeProvider();
// Rooted at a path, showing hidden and system folders
public FileSystemTreeNodeProvider FsProvider { get; } =
new FileSystemTreeNodeProvider(@"C:\Users", showHidden: true);
// Virtual tree from ZIP entries
var (provider, root) = VirtualTreeNodeProvider.FromPaths(
zipFile.Entries.Select(e => e.FullName),
rootName: "archive.zip");<ctrl:BetterPathTreeview
x:Name="MyTreeview"
NodeProvider="{x:Bind FsProvider}"
ShowSearchBox="True"
NodeSelected="OnNodeSelected"
NodeExpanded="OnNodeExpanded"
NodeInvoked="OnNodeInvoked"/>private void OnNodeSelected(object sender, TreeNodeEventArgs e)
{
// e.Path → full path string
// e.Node → TreeNode object
MyStatusBar.Text = e.Path;
}
private void OnNodeExpanded(object sender, TreeNodeEventArgs e)
{
Debug.WriteLine($"Expanded: {e.Path}");
}
private void OnNodeInvoked(object sender, TreeNodeEventArgs e)
{
// double-click or Enter key
OpenFolder(e.Path);
}| Property | Type | Default | Description |
|---|---|---|---|
NodeProvider |
ITreeNodeProvider |
null |
Data source for the tree |
ShowSearchBox |
bool |
true |
Show or hide the search/filter box |
RootIcon |
string? |
null |
Icon override for all root nodes (glyph or image path) |
NodeIcon |
string? |
null |
Icon override for all non-root nodes |
| Property | Type | Description |
|---|---|---|
SelectedNode |
TreeNode? |
Currently selected node |
| Event | Args type | Fired when |
|---|---|---|
NodeSelected |
TreeNodeEventArgs |
User clicks a node |
NodeExpanded |
TreeNodeEventArgs |
User expands a node |
NodeInvoked |
TreeNodeEventArgs |
User double-clicks or presses Enter on a node |
// Expand and scroll to a path in the tree
await myTreeview.RevealPathAsync(@"C:\Windows\System32");
// Full tree reload (keeps provider, discards loaded nodes)
await myTreeview.ReloadAsync();Reads the Windows filesystem lazily. Files are never shown — only folders.
// All drives ("This PC" view)
var provider = new FileSystemTreeNodeProvider();
// Rooted at a specific path
var provider = new FileSystemTreeNodeProvider(@"C:\Projects");
// Show hidden and system folders (rendered at 50% opacity)
var provider = new FileSystemTreeNodeProvider(showHidden: true);
// Rooted + show hidden
var provider = new FileSystemTreeNodeProvider(@"C:\Users", showHidden: true);Hidden/system folders are included when showHidden: true and are automatically shown at 50% opacity thanks to BoolToOpacityConverter in the control's DataTemplate.
Builds a navigable folder tree from a flat list of slash-separated paths.
string[] entries =
[
"2024/01/",
"2024/02/",
"2024/02/report.xml",
"2025/01/backup.zip",
];
var (provider, root) = VirtualTreeNodeProvider.FromPaths(
entries,
rootName: "my-archive.zip");
MyTreeview.NodeProvider = provider;Only the folder structure is exposed. File entries are used to infer folder structure but are not displayed as nodes unless includeFiles: true is passed.
Implement ITreeNodeProvider to connect any data source:
public class FtpTreeProvider : ITreeNodeProvider
{
private readonly FtpClient _client;
public FtpTreeProvider(FtpClient client) => _client = client;
public bool SupportsSearch => false; // lazy remote source
public async Task<IEnumerable<TreeNode>> GetRootsAsync(CancellationToken ct = default)
{
return new[]
{
new TreeNode { Name = "ftp://myserver", FullPath = "/", IsRoot = true }
};
}
public async Task<IEnumerable<TreeNode>> GetChildrenAsync(
TreeNode node, CancellationToken ct = default)
{
var dirs = await _client.ListDirectoriesAsync(node.FullPath, ct);
return dirs.Select(d => new TreeNode
{
Name = d.Name,
FullPath = d.FullPath,
IsLeaf = !d.HasSubdirectories
});
}
}| Property | Type | Description |
|---|---|---|
Name |
string |
Display name shown in the node label |
FullPath |
string |
Full path (filesystem or virtual) — also used for reveal and tooltips |
IsRoot |
bool |
Root node — rendered with drive icon by default |
IsLeaf |
bool |
No children — chevron is hidden |
IsHidden |
bool |
Rendered at 50% opacity (hidden/system folders) |
Icon |
string? |
Per-node icon: Segoe Fluent Icons glyph, .png path, or .svg path |
Children |
List<TreeNode> |
Pre-loaded children (used by virtual provider) |
Tag |
object? |
Arbitrary host data, not used by the control |
Icons are resolved in this order (first non-null wins):
TreeNode.Icon— per-node overrideNodeIcon/RootIcondependency property — control-level override- Built-in default — drive glyph (
\uEDA2) for roots, folder glyph (\uE8B7) for all others
Accepted formats:
// Segoe Fluent Icons glyph
node.Icon = "\uE8B7";
// Absolute path to PNG or SVG
node.Icon = @"C:\MyApp\Assets\folder-special.png";
// ms-appx URI
node.Icon = "ms-appx:///Assets/folder-special.svg";When the user changes an option (e.g. "Show hidden"), create a new provider and assign it:
private void ShowHidden_Changed(object sender, RoutedEventArgs e)
{
bool showHidden = sender is CheckBox cb && cb.IsChecked == true;
FsTreeview.NodeProvider = new FileSystemTreeNodeProvider(showHidden: showHidden);
}Assigning a new NodeProvider automatically triggers a full reload.
See CHANGELOG.md.
MIT — see LICENSE for details.
Matteo Riso — zipgenius.it
Written with Claude AI by Anthropic.