Exemplo n.º 1
0
        private void TreeView_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem currentTreeNode = sender as TreeViewItem;

            if (currentTreeNode == null)
            {
                return;
            }

            if (currentTreeNode.ItemsSource == null)
            {
                return;
            }

            DirInfo parentDirectory = currentTreeNode.Header as DirInfo;

            if (parentDirectory == null)
            {
                return;
            }

            foreach (DirInfo d in currentTreeNode.ItemsSource)
            {
                if (myViewModel.CurrentDirectory.Path.Equals(d.Path))
                {
                    d.IsSelected = true;
                    d.IsExpanded = true;
                    break;
                }
            }
            e.Handled = true;
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="curDir"></param>
 public void ExpandToCurrentNode(DirInfo curDir)
 {
     //expand the current selected node in tree
     //if this is an ancestor of the directory we want to navigate or "My Computer" current node
     if (CurrentTreeItem != null && (curDir.Path.Contains(CurrentTreeItem.Path) ||
                                     CurrentTreeItem.Path == UserInterfaceStrings.FileSystem_MyComputer))
     {
         // expand the current node
         // If the current node is already expanded then first collapse it n then expand it
         CurrentTreeItem.IsExpanded = false;
         CurrentTreeItem.IsExpanded = true;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="evm"></param>
        public FileExplorerViewModel(ExplorerWindowViewModel evm) : base(null)
        {
            _evm = evm;

            //create a node for "my computer"
            // this will be the root for the file system tree
            DirInfo rootNode = new DirInfo(UserInterfaceStrings.FileSystem_MyComputer);

            rootNode.Path         = UserInterfaceStrings.FileSystem_MyComputer;
            _evm.CurrentDirectory = rootNode; //make root node as the current directory

            SystemDirectorySource = new List <DirInfo> {
                rootNode
            };
        }
Exemplo n.º 4
0
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                DirInfo nodeToExpand = value as DirInfo;
                if (nodeToExpand == null)
                {
                    return(null);
                }

                //return the subdirectories of the Current Node
                if ((ObjectType)nodeToExpand.DirType == ObjectType.MyComputer)
                {
                    return((from sd in FileSystemExplorerService.GetRootDirectories()
                            select new DirInfo(sd)).ToList());
                }
                else
                {
                    return((from dirs in FileSystemExplorerService.GetChildDirectories(nodeToExpand.Path)
                            select new DirInfo(dirs)).ToList());
                }
            }
            catch { return(null); }
        }