Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System;
  16. using System.Globalization;
  17. using System.Windows;
  18. using System.Windows.Data;
  19. using System.Windows.Media.Imaging;
  20. using System.IO;
  21.  
  22. namespace Wpf_lab2_zawadkaf
  23. {
  24. /// <summary>
  25. /// Interaction logic for MainWindow.xaml
  26. /// </summary>
  27.  
  28.  
  29.  
  30. public partial class MainWindow : Window
  31. {
  32. public MainWindow()
  33. {
  34. InitializeComponent();
  35. DriveInfo[] drives = DriveInfo.GetDrives();
  36. foreach (DriveInfo driveInfo in drives)
  37. trvStructure.Items.Add(CreateTreeItem(driveInfo));
  38. }
  39.  
  40. public void TreeViewItem_Expanded(object sender, RoutedEventArgs e)
  41. {
  42. TreeViewItem item = e.Source as TreeViewItem;
  43. if ((item.Items.Count == 1) && (item.Items[0] is string))
  44. {
  45. item.Items.Clear();
  46.  
  47. DirectoryInfo expandedDir = null;
  48. if (item.Tag is DriveInfo)
  49. expandedDir = (item.Tag as DriveInfo).RootDirectory;
  50. if (item.Tag is DirectoryInfo)
  51. expandedDir = (item.Tag as DirectoryInfo);
  52. try
  53. {
  54. foreach (DirectoryInfo subDir in expandedDir.GetDirectories())
  55. item.Items.Add(CreateTreeItem(subDir));
  56. }
  57. catch { }
  58. }
  59. }
  60.  
  61. private TreeViewItem CreateTreeItem(object o)
  62. {
  63. TreeViewItem item = new TreeViewItem();
  64. item.Header = o.ToString();
  65. item.Tag = o;
  66. item.Items.Add("Loading...");
  67. return item;
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement