Loading...
Loading...
Guide for implementing Syncfusion NavigationView control in Windows Forms for breadcrumb navigation and hierarchical path tracking. Use when building file explorers, folder browsers, or file browser-style interfaces with breadcrumb trails. Covers breadcrumb navigation, dropdown navigation, history tracking, and hierarchical bar structures for path-based location tracking with dropdown child selection.
npx skill4agent add syncfusion/winforms-ui-components-skills syncfusion-winforms-navigation-viewMyComputer > C: > Program Files > AppNavigationView[Icon] MyComputer > C: > Program Files > App [History ▼]
└─────┬─────┘
└─ Click arrow to see child Bars dropdownSyncfusion.Windows.Forms.Toolsusing Syncfusion.Windows.Forms.Tools;
using Syncfusion.Windows.Forms.Tools.Navigation;
// Create NavigationView
NavigationView navigationView1 = new NavigationView();
navigationView1.Width = 400;
navigationView1.Height = 25;
navigationView1.Location = new System.Drawing.Point(20, 20);
// Create root Bar
Bar rootBar = new Bar();
rootBar.Text = "MyComputer";
// Create child Bars
Bar driveC = new Bar();
driveC.Text = "Local Disk (C:)";
Bar driveD = new Bar();
driveD.Text = "Local Disk (D:)";
Bar programFiles = new Bar();
programFiles.Text = "Program Files";
// Build hierarchy
rootBar.Bars.AddRange(new Bar[] { driveC, driveD });
driveC.Bars.Add(programFiles);
// Add root to NavigationView
navigationView1.Bars.Add(rootBar);
// Set initial selection
navigationView1.SelectedBar = rootBar;
// Add to form
this.Controls.Add(navigationView1);// Root = Computer
Bar computer = new Bar { Text = "This PC" };
// Drives
Bar cDrive = new Bar { Text = "Local Disk (C:)" };
Bar dDrive = new Bar { Text = "Local Disk (D:)" };
// Common folders
Bar users = new Bar { Text = "Users" };
Bar documents = new Bar { Text = "Documents" };
Bar downloads = new Bar { Text = "Downloads" };
// Build hierarchy
computer.Bars.AddRange(new Bar[] { cDrive, dDrive });
cDrive.Bars.Add(users);
users.Bars.AddRange(new Bar[] { documents, downloads });
navigationView1.Bars.Add(computer);
navigationView1.SelectedBar = computer;public void LoadFoldersFromPath(string rootPath, Bar parentBar)
{
try
{
var directories = Directory.GetDirectories(rootPath);
foreach (var dir in directories)
{
Bar childBar = new Bar();
childBar.Text = Path.GetFileName(dir);
childBar.Tag = dir; // Store full path
parentBar.Bars.Add(childBar);
// Optionally load sub-folders
// LoadFoldersFromPath(dir, childBar);
}
}
catch (UnauthorizedAccessException)
{
// Handle permission errors
}
}
// Usage
Bar rootBar = new Bar { Text = "C:", Tag = @"C:\" };
LoadFoldersFromPath(@"C:\", rootBar);
navigationView1.Bars.Add(rootBar);// Enable history button
navigationView1.ShowHistoryButtons = true;
// Handle BarSelected event to track navigation
navigationView1.BarSelected += (sender, e) =>
{
string currentPath = GetFullPath(navigationView1.SelectedBar);
Console.WriteLine($"Navigated to: {currentPath}");
// Update UI based on selection
LoadContent(currentPath);
};
// Helper to build full path
private string GetFullPath(Bar bar)
{
List<string> path = new List<string>();
Bar current = bar;
while (current != null)
{
path.Insert(0, current.Text);
current = current.Parent as Bar;
}
return string.Join(" > ", path);
}// Create custom search button
CustomButton searchButton = new CustomButton();
searchButton.Name = "searchButton";
searchButton.Image = Properties.Resources.SearchIcon; // Your icon
searchButton.Appearance = ButtonAppearance.Office2007;
// Handle click
searchButton.Click += (sender, e) =>
{
// Show search dialog or panel
ShowSearchPanel();
};
// Add to NavigationView
navigationView1.Controls.Add(searchButton);| Property | Type | Description |
|---|---|---|
| | Collection of root-level Bars |
| | Currently displayed Bar in the path |
| | Show/hide history dropdown button |
| | Apply Office2007, Vista, or Metro styling |
| | Image collection for Bar icons |
| Property | Type | Description |
|---|---|---|
| | Display text for the Bar |
| | Index in NavigationView.ImageList |
| | Child Bars of this Bar |
| | Store custom data (e.g., full path) |
| Event | Description | Common Use |
|---|---|---|
| Fires when user selects a Bar | Load content for selected location |
| Fires before dropdown shows | Customize popup items, set max items |
| User clicks the control | Handle general interaction |
// Enable edit mode
navigationView1.AllowEdit = true; // If property exists
// Handle path changes
navigationView1.BarSelected += (sender, e) =>
{
if (navigationView1.SelectedBar.Tag is string path)
{
LoadDirectoryContents(path);
}
};Bar settings = new Bar { Text = "Settings" };
Bar appearance = new Bar { Text = "Appearance" };
Bar colors = new Bar { Text = "Colors" };
Bar fonts = new Bar { Text = "Fonts" };
settings.Bars.Add(appearance);
appearance.Bars.AddRange(new Bar[] { colors, fonts });
navigationView1.Bars.Add(settings);
navigationView1.SelectedBar = settings;// Setup ImageList
ImageList imgList = new ImageList();
imgList.Images.Add("folder", Properties.Resources.FolderIcon);
imgList.Images.Add("doc", Properties.Resources.DocumentIcon);
navigationView1.ImageList = imgList;
// Create hierarchy with images
Bar root = new Bar { Text = "Documents", ImageIndex = 0 };
Bar contracts = new Bar { Text = "Contracts", ImageIndex = 0 };
Bar invoices = new Bar { Text = "Invoices", ImageIndex = 0 };
root.Bars.AddRange(new Bar[] { contracts, invoices });
navigationView1.Bars.Add(root);navigationView1.BarPopup += (sender, e) =>
{
// Limit items to 10 for better UX
e.MaximumItemsToDisplay = 10;
// Cancel popup for specific Bars
if (e.CurrentBar.Text == "EmptyFolder")
{
e.Cancel = true;
}
};navigationView1.BarsSelectedBarImageListImageIndexBarsparentBar.Bars.Add(childBar)navigationView1.ShowHistoryButtons = trueVisualStylenavigationView1.VisualStyle = VisualStyles.Office2007;BarSelected