示例#1
0
        public MainWindow()
        {
            InitializeComponent();

            foreach (string path in Directory.GetLogicalDrives())
            {
                myTreeItem folder = new myTreeItem(path);
                folder.Header = path;
                folder.Tag    = path;
                folder.Items.Add(emptyItem);
                folder.Expanded += new RoutedEventHandler(folderExpanded);
                treeMenu.Items.Add(folder);
            }
        }
示例#2
0
        void folderExpanded(object sender, RoutedEventArgs e)
        {
            myTreeItem folder = (myTreeItem)sender;

            if (folder.Items.Count == 1 && folder.Items[0] == emptyItem)
            {
                folder.Items.Clear();
                try
                {
                    foreach (string path in Directory.GetDirectories(folder.Tag.ToString()))
                    {
                        myTreeItem subFolder = new myTreeItem(path);
                        subFolder.Header = path.Substring(path.LastIndexOf("\\") + 1);
                        subFolder.Tag    = path;
                        subFolder.Items.Add(emptyItem);
                        subFolder.Expanded += new RoutedEventHandler(folderExpanded);
                        folder.Items.Add(subFolder);
                    }
                }
                catch (Exception) { }
            }
        }