示例#1
0
        public void BuildParentNode()
        {
            DirectoryInfo DIR = new DirectoryInfo(GlobalVariable.objMainWindowVM.SavedData.DriveLetter);

            LsRootTreeViewItem = new ObservableCollection <RootTreeViewItem>();

            RootTreeViewItem Parent = new RootTreeViewItem();

            Parent.Header     = DIR.Name;
            Parent.Path       = DIR.FullName;
            Parent.Type       = DIR.GetType().Name;
            Parent.IsExpanded = false;
            LsRootTreeViewItem.Add(Parent);

            Parent.LsChildrenNode = new ObservableCollection <RootTreeViewItem>();
            foreach (DirectoryInfo DR in DIR.GetDirectories())
            {
                if (!DR.Attributes.ToString().Contains("Hidden"))
                {
                    RootTreeViewItem ParenNode = new RootTreeViewItem();
                    ParenNode.Header     = DR.Name;
                    ParenNode.Path       = DR.FullName;
                    ParenNode.Type       = DR.GetType().Name;
                    ParenNode.IsExpanded = false;
                    Parent.LsChildrenNode.Add(ParenNode);

                    ParenNode.LsChildrenNode = new ObservableCollection <RootTreeViewItem>();
                    foreach (DirectoryInfo CDIR in DR.GetDirectories())
                    {
                        RootTreeViewItem ChildrenNode = new RootTreeViewItem();
                        ChildrenNode.IsExpanded = false;
                        ChildrenNode.Header     = CDIR.Name;
                        ChildrenNode.Path       = CDIR.FullName;
                        ChildrenNode.Type       = CDIR.GetType().Name;
                        ParenNode.LsChildrenNode.Add(ChildrenNode);
                    }
                }
            }
            foreach (FileInfo DR in DIR.GetFiles())
            {
                if (!DR.Attributes.ToString().Contains("Hidden"))
                {
                    RootTreeViewItem ParenNode = new RootTreeViewItem();
                    ParenNode.Header     = DR.Name;
                    ParenNode.Path       = DR.FullName;
                    ParenNode.Type       = DR.GetType().Name;
                    ParenNode.IsExpanded = false;
                    Parent.LsChildrenNode.Add(ParenNode);
                }
            }
        }
示例#2
0
        private void GetChiledNodes()
        {
            if (LsChildrenNode != null)
            {
                foreach (var CTVI in LsChildrenNode)
                {
                    if (CTVI.Type == "DirectoryInfo")
                    {
                        DirectoryInfo DIR = new DirectoryInfo(CTVI.Path);
                        CTVI.LsChildrenNode = new ObservableCollection <RootTreeViewItem>();
                        foreach (DirectoryInfo CDIR in DIR.GetDirectories())
                        {
                            if (!CDIR.Attributes.ToString().Contains("Hidden"))
                            {
                                RootTreeViewItem CTVI1 = new RootTreeViewItem();
                                CTVI1.LsChildrenNode = new ObservableCollection <RootTreeViewItem>();
                                CTVI1.Header         = CDIR.Name;
                                CTVI1.Path           = CDIR.FullName;
                                CTVI1.Type           = CDIR.GetType().Name;
                                CTVI1.IsExpanded     = false;
                                CTVI.LsChildrenNode.Add(CTVI1);
                            }
                        }


                        foreach (FileInfo FL in DIR.GetFiles())
                        {
                            if (!FL.Attributes.ToString().Contains("Hidden"))
                            {
                                RootTreeViewItem CTVI1 = new RootTreeViewItem();
                                //CTVI1. = new ObservableCollection<RootTreeViewItem>();
                                CTVI1.IsExpanded = false;
                                CTVI1.Header     = FL.Name;
                                CTVI1.Path       = FL.FullName;
                                CTVI1.Type       = FL.GetType().Name;
                                CTVI.LsChildrenNode.Add(CTVI1);
                            }
                        }
                    }
                }
            }
        }