// 트리뷰는 위의 방법처럼 조작이 불가능함.. 왼쪽 컨트롤의 공통점은 IsSynchronizedWithCurrentItem로 모두 싱크가 이루어지는데 // 트리뷰는 이를 지원하지 않음. // 따라서 아래방법으로 해야함... 더 좋은방법있나? private void treeView1_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { TreeView tv = sender as TreeView; var selectedItem = tv.SelectedItem; if (selectedItem is Computer) { Computer computer = selectedItem as Computer; MessageBox.Show(computer.ComputerName); } else if (selectedItem is Drive) { Drive drive = selectedItem as Drive; MessageBox.Show(drive.DriveName); } else if (selectedItem is Entity) { Entity entity = selectedItem as Entity; MessageBox.Show(entity.EntityName); } }
public ViewModel() { Drive c_Drive = new Drive("C Drive"); Drive d_Drive = new Drive("D Drive"); Entity folder1 = new Entity("Folder1", RandomDay()); Entity folder2 = new Entity("Folder2", RandomDay()); Entity folder3 = new Entity("Folder3", RandomDay()); Entity folder4 = new Entity("Folder4", RandomDay()); Entity folder5 = new Entity("Folder5", RandomDay()); Entity folder6 = new Entity("Folder6", RandomDay()); Entity file1 = new Entity("file 1", RandomDay()); Entity file2 = new Entity("file 2", RandomDay()); Entity file3 = new Entity("file 3", RandomDay()); Entity file4 = new Entity("file 4", RandomDay()); Entity file5 = new Entity("file 5", RandomDay()); Entity file6 = new Entity("file 6", RandomDay()); Entity file7 = new Entity("file 7", RandomDay()); Entity file8 = new Entity("file 8", RandomDay()); folder1.Children.Add(file1); folder1.Children.Add(file2); folder1.Children.Add(file3); folder2.Children.Add(file4); folder2.Children.Add(file2); folder2.Children.Add(file1); folder3.Children.Add(file2); folder3.Children.Add(file3); folder3.Children.Add(file4); folder4.Children.Add(file6); folder4.Children.Add(file5); folder4.Children.Add(file3); folder5.Children.Add(file5); folder6.Children.Add(file1); folder6.Children.Add(file3); file3.Children.Add(new Entity("File", DateTime.Now)); c_Drive.Entities.Add(folder1); c_Drive.Entities.Add(folder2); c_Drive.Entities.Add(folder3); d_Drive.Entities.Add(folder4); d_Drive.Entities.Add(folder5); d_Drive.Entities.Add(folder6); Computer com1 = new Computer("Com1"); Computer com2 = new Computer("Com2"); com1.Drives.Add(c_Drive); com1.Drives.Add(d_Drive); com2.Drives.Add(c_Drive); com2.Drives.Add(d_Drive); Computers.Add(com1); Computers.Add(com2); }