Data Binding
The RadBreacrumb provides extensive data binding support. You can display flat data collections as well as hierarchical data. The following properties are exposed to help you implement data binding scenarios with the control:
-
IconPath - Gets or sets a path to a value on the source object to serve as the BreadcrumbItem.Image.
-
TextModePath - Gets or sets a path to a value on the source object to serve as the string representation of the BreadcrumbItem in text mode
Bind the Breadcrumb to a flat collection of business objects
The following example will show you how to bind a Breadcrumb control to a flat collection of business objects. The final result should look like the snapshot below:

-
First, you need to include the following assemblies in your XAML declaration:
- Telerik.Windows.Controls
- Telerik.Windows.Controls.Navigation
-
Create a new class named ExplorerItem :
Example 1: Creating a model for the breadcrumb items
C#public class ExplorerItem { public string Header { get; set; } public string PreviewHeader { get; set; } public string Path { get; set; } public ImageSource IconPath { get; set;} } -
Create a new class MainViewModel - it will contain the collection of ExplorerItems that we will use as ItemsSource for the RadBreadcrumb as well as a string property - Header
Example 2: Creating a main view model
C#public class MainViewModel { public ObservableCollection<ExplorerItem> Items { get; set; } public string Header { get; set; } public MainViewModel() { ImageSourceConverter isc = new ImageSourceConverter(); this.Header = "MyComputer"; this.Items = new ObservableCollection<ExplorerItem>(); ExplorerItem personalInfo = new ExplorerItem() { Header = "Personal Folders", IconPath = (ImageSource)isc.ConvertFromString("../../Images/1PersonalFolders.png"), Path = "PersonalFolders" }; this.Items.Add(personalInfo); ExplorerItem programFiles = new ExplorerItem() { Header = "Program Files", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Path = "ProgramFiles" }; this.Items.Add(programFiles); ExplorerItem programFiles86 = new ExplorerItem() { Header = "Program Files(86)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Path = "ProgramFiles(86)" }; this.Items.Add(programFiles86); ExplorerItem downloads = new ExplorerItem() { Header = "Downloads", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Path = "Downloads" }; this.Items.Add(downloads); ExplorerItem localHard = new ExplorerItem() { Header = "Local Disk (C:)", Path = "LocalDisk(C:)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/HardDrive16.png") }; this.Items.Add(localHard); ExplorerItem localHard2 = new ExplorerItem() { Header = "Local Disk (D:)", Path = "LocalDisk(D:)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/HardDrive16.png") }; this.Items.Add(localHard2); ExplorerItem desktop = new ExplorerItem() { Header = "Desktop", Path = "Desktop", IconPath = (ImageSource)isc.ConvertFromString("../../Images/Desktop.png") }; this.Items.Add(desktop); } } -
Use the MainViewModel as data context for a RadBreadcrumb control:
Example 3: Setting up the DataContex of the breadcrumb
XAML<FrameworkElement.DataContext> <vm:MainViewModel /> </FrameworkElement.DataContext> <Grid Background="White"> <telerik:RadBreadcrumb VerticalAlignment="Top" ItemsSource="{Binding Items}" Header="{Binding}" TextModePath="Path" ImagePath="IconPath" IsIconVisible="True"> <telerik:RadBreadcrumb.HeaderTemplate> <DataTemplate> <TextBlock FontWeight="Bold" Foreground="Orange" Text="{Binding Header}" /> </DataTemplate> </telerik:RadBreadcrumb.HeaderTemplate> <telerik:RadBreadcrumb.ItemTemplate> <DataTemplate> <TextBlock Foreground="Purple" Text="{Binding Header}" /> </DataTemplate> </telerik:RadBreadcrumb.ItemTemplate> </telerik:RadBreadcrumb> </Grid>
Display hierarchical data in the Breadcrumb control
-
Extend the ExplorerItem by adding a collection of ExplorerItems.
Example 4: Extending the breadcrumb items' model
C#public class ExplorerItem { public string Header { get; set; } public string PreviewHeader { get; set; } public string Path { get; set; } public ImageSource IconPath { get; set; } public ObservableCollection<ExplorerItem> Children { get; set; } public ExplorerItem() { this.Children = new ObservableCollection<ExplorerItem>(); } } -
Create a MainViewModel class to define a hierarchical data collection of ExplorerItems:
Example 5: Creating the main view model
C#public class MainViewModel { public ObservableCollection<ExplorerItem> Items { get; set; } public ExplorerItem Root { get; set; } public MainViewModel() { this.Items = new ObservableCollection<ExplorerItem>(); this.LoadItems(); } public void LoadItems() { ImageSourceConverter isc = new ImageSourceConverter(); ExplorerItem personalInfo = new ExplorerItem() { Header = "Personal Folders", IconPath = (ImageSource)isc.ConvertFromString("../../Images/1PersonalFolders.png"), Children = new ObservableCollection<ExplorerItem>() { new ExplorerItem() {Header = "Deleted Items(6)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/2DeletedItems.png"), Path = "DeletedItems"}, new ExplorerItem() {Header = "Drafts", IconPath = (ImageSource)isc.ConvertFromString("../../Images/3Drafts.png"), Path = "Drafts"}, new ExplorerItem() {Header = "Inbox(14)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/4Inbox.png"), Path = "Inbox", Children = new ObservableCollection<ExplorerItem>() { new ExplorerItem() {Header = "Folders", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Folders"}, } }, new ExplorerItem() {Header = "Junk E-mails", IconPath = (ImageSource)isc.ConvertFromString("../../Images/junk.png"), Path = "JunkEmails"}, new ExplorerItem() {Header = "Outbox", IconPath = (ImageSource)isc.ConvertFromString("../../Images/outbox.png"), Path = "Outbox"}, new ExplorerItem() {Header = "Sent Items", IconPath = (ImageSource)isc.ConvertFromString("../../Images/sent.png"), Path = "SentItems"}, new ExplorerItem() {Header = "Search Folder", IconPath = (ImageSource)isc.ConvertFromString("../../Images/searchFolder.png"), Path = "SearchFolder", Children = new ObservableCollection<ExplorerItem>() { new ExplorerItem() {Header = "From Follow up", IconPath = (ImageSource)isc.ConvertFromString("../../Images/search.png"), Path = "FromFollowup"}, new ExplorerItem() {Header = "Large Mail", IconPath = (ImageSource)isc.ConvertFromString("../../Images/search.png"), Path = "LargeMail"}, new ExplorerItem() {Header = "Unread Mail", IconPath = (ImageSource)isc.ConvertFromString("../../Images/search.png"), Path = "UnreadMail"}, } } }, Path = "PersonalFolders" }; ExplorerItem programFiles = new ExplorerItem() { Header = "Program Files", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Children = new ObservableCollection<ExplorerItem>() { new ExplorerItem() { Header = "Microsoft", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Microsoft" }, new ExplorerItem() { Header = "Microsoft.NET", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Microsoft.NET" }, new ExplorerItem() { Header = "Internet Explorer", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Path = "InternetExplorer", Children = new ObservableCollection<ExplorerItem>(){ new ExplorerItem() {Header = "SIGNUP", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "SIGNUP"} } } }, Path = "ProgramFiles" }; ExplorerItem programFiles86 = new ExplorerItem() { Header = "Program Files(86)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Children = new ObservableCollection<ExplorerItem>() { new ExplorerItem() { Header = "Microsoft", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Microsoft" }, new ExplorerItem() { Header = "Microsoft.NET", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Microsoft.NET" }, new ExplorerItem() { Header = "Skype", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Path = "Skype", Children = new ObservableCollection<ExplorerItem>(){ new ExplorerItem() {Header = "Phone", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Phone"}, new ExplorerItem() {Header = "Toolbars", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Toolbars"}, new ExplorerItem() {Header = "Plugin Manager", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "PluginManager"} } }, new ExplorerItem() { Header = "Notepad++", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Path = "Notepad++", Children = new ObservableCollection<ExplorerItem>(){ new ExplorerItem() {Header = "localization", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "localization"}, new ExplorerItem() {Header = "plugins", IconPath = (ImageSource)isc.ConvertFromString("../../Images/junk.png"), Path = "plugins"} } } }, Path = "ProgramFiles(86)" }; ExplorerItem downloads = new ExplorerItem() { Header = "Downloads", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder2.png"), Children = new ObservableCollection<ExplorerItem>() { new ExplorerItem() { Header = "Music", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Music" }, new ExplorerItem() { Header = "Movies", IconPath = (ImageSource)isc.ConvertFromString("../../Images/folder.png"), Path = "Movies" } }, Path = "Downloads" }; ExplorerItem localHard = new ExplorerItem() { Header = "Local Disk (C:)", Path = "LocalDisk(C:)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/HardDrive16.png"), Children = new ObservableCollection<ExplorerItem>() { personalInfo, programFiles, programFiles86, downloads } }; ExplorerItem localHard2 = new ExplorerItem() { Header = "Local Disk (D:)", Path = "LocalDisk(D:)", IconPath = (ImageSource)isc.ConvertFromString("../../Images/HardDrive16.png") }; ExplorerItem computer = new ExplorerItem() { Header = "Computer", Path = "Computer", IconPath = (ImageSource)isc.ConvertFromString("../../Images/Computer.png"), Children = new ObservableCollection<ExplorerItem>() { localHard, localHard2 } }; ExplorerItem computer2 = new ExplorerItem() { Header = "Computer2", Path = "Computer2", Children = new ObservableCollection<ExplorerItem>() { localHard, localHard2 } }; this.Root = new ExplorerItem() { Header = "Desktop", Path = "Desktop", IconPath = (ImageSource)isc.ConvertFromString("../../Images/Desktop.png"), Children = new ObservableCollection<ExplorerItem>() { computer, computer2 } }; this.Items = new ObservableCollection<ExplorerItem>() { this.Root }; } } -
Display the hierarchical data collection in the RadBreadcrumb control using:
-
HierarchicalDataTemplates: Example 6: Using HierarchicalDataTemplates
XAML<FrameworkElement.DataContext> <vm:MainViewModel /> </FrameworkElement.DataContext> <Grid Background="White"> <telerik:RadBreadcrumb VerticalAlignment="Top" Header="{Binding Root}" ImagePath="IconPath" IsIconVisible="True" ItemsSource="{Binding Root.Children}" TextModePath="Path"> <telerik:RadBreadcrumb.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding Header}" /> </DataTemplate> </telerik:RadBreadcrumb.HeaderTemplate> <telerik:RadBreadcrumb.ItemTemplate> <HierarchicalDataTemplate ItemsSource="{Binding Children}"> <HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Header}" /> </DataTemplate> </HierarchicalDataTemplate.ItemTemplate> <TextBlock Text="{Binding Header}" /> </HierarchicalDataTemplate> </telerik:RadBreadcrumb.ItemTemplate> </telerik:RadBreadcrumb> </Grid> -
the Breadcrumb properties exposed to facilitate your efforts in populating the control with hierarchical data:
-
HeaderMemberPath - Gets or sets a path to a value on the source object to serve as the BreadcrumbItem.Header.
-
HierarchicalItemsSource - Gets or sets a path to a value on the source object to serve as the BreadcrumbItem 's ItemsSource collection.
-
HierarchicalMemberPath - Gets or sets a path to a value on the source object to serve as the BreadcrumbItem.DropDownHeader.
Example 7: Using HierarchicalMemberPath
XAML<telerik:RadBreadcrumb VerticalAlignment="Top" Header="{Binding Root}" HeaderMemberPath="Header" HierarchicalItemsSource="Children" HierarchicalMemberPath="Header" ImagePath="IconPath" IsIconVisible="True" ItemsSource="{Binding Root.Children}" TextModePath="Path" />
-
-
In both approaches the final result should look like this:
