NodeDataEditor.xaml.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using Helper;
  5. namespace Tree
  6. {
  7. /// <summary>
  8. /// NodeDataEditor.xaml 的交互逻辑
  9. /// </summary>
  10. public partial class NodeDataEditor: UserControl
  11. {
  12. public NodeDataEditor()
  13. {
  14. this.InitializeComponent();
  15. string[] nodeTypes = Enum.GetNames(typeof (NodeType));
  16. this.cbType.ItemsSource = nodeTypes;
  17. }
  18. public TreeNodeViewModel ViewModel
  19. {
  20. get
  21. {
  22. return this.DataContext as TreeNodeViewModel;
  23. }
  24. }
  25. private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
  26. {
  27. if (this.ViewModel == null)
  28. {
  29. return;
  30. }
  31. this.cbType.SelectedIndex = EnumHelper.EnumIndex<NodeType>(this.ViewModel.Type);
  32. }
  33. private void CbType_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  34. {
  35. if (this.cbType.SelectedValue == null)
  36. {
  37. this.ViewModel.Type = 0;
  38. return;
  39. }
  40. this.ViewModel.Type =
  41. (int) Enum.Parse(typeof (NodeType), this.cbType.SelectedValue.ToString().Trim());
  42. }
  43. }
  44. }