Exemple #1
0
        /// <summary>
        /// Expands this directory and finds all the childrens.
        /// </summary>
        /// <exception cref="System.NotImplementedException"></exception>
        private void Expand()
        {
            if (this.Type == DirectoryItemType.FILE)
            {
                return;
            }

            //Find all childrens
            //Solution 1
            ObservableCollection <DirectoryItemViewModel> childrens = new ObservableCollection <DirectoryItemViewModel>();
            List <DiretoryItem> items = DirectoryStructure.GetDirectoryContents(this.FullPath);
            ObservableCollection <DirectoryItemViewModel> grandChildren = new ObservableCollection <DirectoryItemViewModel>();

            grandChildren  = items.Select(content => new DirectoryItemViewModel(content.FullPath, content.Type)) as ObservableCollection <DirectoryItemViewModel>;
            this.Childrens = grandChildren;

            //Solution 2
            this.Childrens = new ObservableCollection <DirectoryItemViewModel>
                                 (DirectoryStructure.GetDirectoryContents(FullPath).Select
                                     (content => new DirectoryItemViewModel(content.FullPath, content.Type)));

            //Solution3
            var children = DirectoryStructure.GetDirectoryContents(this.FullPath);

            this.Childrens = new ObservableCollection <DirectoryItemViewModel>(
                children.Select(content => new DirectoryItemViewModel(content.FullPath, content.Type)));
        }
        public DirectoryStructureViewModel()
        {
            //Get the logical drives
            var children      = DirectoryStructure.GetLogicalDrives();
            var grandchildren = children.Select(drive => new DirectoryItemViewModel(drive.FullPath, drive.Type));

            //Create the tree view
            this.Items = new ObservableCollection <DirectoryItemViewModel>(grandchildren);
        }