예제 #1
0
 // переобределение события для заполнения вложеенных узлов
 protected override void OnExpanded(RoutedEventArgs args)
 {
     base.OnExpanded(args);
     foreach (object obj in Items)
     {
         DirectoryTreeViewItem item = obj  as DirectoryTreeViewItem;
         item.Populate();
     }
 }
예제 #2
0
 public void RefreshTree()
 {
     BeginInit();
     Items.Clear();
     // получаем информ. о дисках.
     DriveInfo[] drives = DriveInfo.GetDrives();
     foreach (DriveInfo drive in drives)
     {
         char chDrive = drive.Name.ToUpper()[0];
         DirectoryTreeViewItem item = new  DirectoryTreeViewItem(drive.RootDirectory);
         // если диск готов выводим метку тома, иначе только тип
         if (chDrive != 'A' && chDrive != 'B' && drive.IsReady && drive.VolumeLabel.Length > 0)
         {
             item.Text = String.Format("{0}  ({1})", drive.VolumeLabel, drive.Name);
         }
         else
         {
             item.Text = String.Format("{0}  ({1})", drive.DriveType, drive.Name);
         }
         // Выбираем картинку для диска.
         if (chDrive == 'A' || chDrive == 'B')
         {
             item.SelectedImage = item.UnselectedImage = new BitmapImage(new Uri("C:/Users/7777/source/repos/Chapter16/Chapter16/35FLOPPY.BMP"));
         }
         else
         if (drive.DriveType == DriveType.CDRom)
         {
             item.SelectedImage = item.UnselectedImage = new BitmapImage(new Uri("C:/Users/7777/source/repos/Chapter16/Chapter16/CDDRIVE.BMP"));
         }
         else
         {
             item.SelectedImage = item.UnselectedImage = new BitmapImage(new Uri("C:/Users/7777/source/repos/Chapter16/Chapter16/DRIVE.BMP"));
         }
         Items.Add(item);
         // зАполняем информацию о каталогах
         if (chDrive != 'A' && chDrive != 'B' && drive.IsReady)
         {
             item.Populate();
         }
     }
     EndInit();
 }
예제 #3
0
파일: Program.cs 프로젝트: Ghoost17/WPF2020
        void TreeViewOnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> args)
        {
            // получаем выделенный узел
            DirectoryTreeViewItem item = args.NewValue as DirectoryTreeViewItem;

            // очищаем DockPanel.
            stack.Children.Clear();
            // заполняем снова.
            FileInfo[] infos;
            try
            {
                infos = item.DirectoryInfo.GetFiles();
            }
            catch
            {
                return;
            }
            foreach (FileInfo info in infos)
            {
                TextBlock text = new TextBlock();
                text.Text = info.Name;
                stack.Children.Add(text);
            }
        }