Example #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var treeItem = value as TreeItem;

            if (treeItem == null)
            {
                if (value != null)
                {
                    throw new ArgumentException("Illegal item type: '{0}'", value.GetType().FullName);
                }
                else
                {
                    return(null);
                }
                ////throw new ArgumentException("Illegal item type: '(null)'");
            }

            if (treeItem is DriveTreeItem)
            {
                DriveTreeItem driveItem = treeItem as DriveTreeItem;
                switch (driveItem.DriveType)
                {
                case DriveType.CDRom:
                    return(cdrom);

                case DriveType.Fixed:
                    return(drive);

                case DriveType.Network:
                    return(netDrive);

                case DriveType.NoRootDirectory:
                    return(drive);

                case DriveType.Ram:
                    return(ram);

                case DriveType.Removable:
                    return(removable);

                case DriveType.Unknown:
                    return(drive);
                }
            }
            else
            {
                return(folder);
            }

            return(null);
        }
Example #2
0
        private void Init()
        {
            this.root = new TreeItem("root", null);
            var systemDrives = DriveInfo.GetDrives();

            foreach (var sd in systemDrives)
            {
                var item = new DriveTreeItem(sd.Name, sd.DriveType, this.root);
                item.Children.Add(new TreeItem(EmptyItemName, item));

                this.root.Children.Add(item);
            }

            this.Root = this.root; // to notify UI
        }