Click here to Skip to main content
15,881,413 members
Articles / Desktop Programming / WPF

WPF Breadcrumb Folder TextBox

Rate me:
Please Sign up or sign in to vote.
4.41/5 (10 votes)
15 Jan 2009LGPL36 min read 100.6K   1.7K   71  
This article provides an implementation of a WPF Breadcrumb control, and describes how to develop one.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using QuickZip.UserControls.Breadcrumb.Presenter;
using QuickZip.UserControls.Breadcrumb.View;
using QuickZip.UserControls.Breadcrumb.Framework;

namespace BreadcrumbTest2
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {        
        public Window1()
        {
            InitializeComponent();
            this.AddHandler(RadioButton.CheckedEvent, new RoutedEventHandler(RadioButton_Checked));
        }

        private void Animal()
        {
            AnimalPresenter animalRoot = new AnimalPresenter();

            animalRoot.AddRoot();
            animalRoot.Add(new AnimalPresenter(animalRoot, "cat3"));
            animalRoot.Add("cat2\\dog2\\rat2\\cat3\\dog3\\rat3\\");
            animalRoot.AddSeparator();

            breadcrumb.SwitchPresenter(animalRoot);
            breadcrumb.Items.Clear();
        }

        private void Folder()
        {
            FolderPresenter folderRoot = new FolderPresenter();
            folderRoot.AddRoot();
            folderRoot.Add(Environment.UserName + "\\Downloads");            
            folderRoot.AddSeparator();
            
            breadcrumb.SwitchPresenter(folderRoot);               

            //dropdown items.
            breadcrumb.Items.Add("C:\\");
            breadcrumb.Items.Add("C:\\Temp\\");
            breadcrumb.Items.Add("D:\\");
        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {

            if (e.OriginalSource is RadioButton)
            {
                string root = (e.OriginalSource as RadioButton).Content as string;

                switch (root)
                {
                    case "Animal" :
                        Animal();
                        breadcrumb.SelectedFolder = "cat2\\dog1\\rat3";   
                        break;

                    case "Folder" :
                        Folder();
                        breadcrumb.SelectedFolder = "";         
                        break;
                }
                                                                                                                                                                                 #region Easter egg                
                breadcrumb.IsTrailDirEnabled = root == "Animal"; 
               
                                                                                                                                                                                 #endregion
            }            
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            breadcrumb.RefreshClicked += (RoutedEventHandler)delegate { MessageBox.Show("Refresh clicked."); };
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Folder();
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder
Hong Kong Hong Kong

Comments and Discussions