NodeDataEditor.xaml.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 : IEventNotifyView
  11. {
  12. private NodeDataEditorViewModel nodeDataEditorViewModel;
  13. public NodeDataEditor()
  14. {
  15. this.InitializeComponent();
  16. string[] nodeTypes = Enum.GetNames(typeof (NodeType));
  17. this.cbType.ItemsSource = nodeTypes;
  18. }
  19. public NodeDataEditorViewModel NodeDataEditorViewModel
  20. {
  21. get
  22. {
  23. return this.nodeDataEditorViewModel;
  24. }
  25. set
  26. {
  27. this.nodeDataEditorViewModel = value;
  28. this.nodeDataEditorViewModel.EventNotifyView = this;
  29. this.TreeNodeViewModel = this.nodeDataEditorViewModel.TreeNodeViewModel;
  30. }
  31. }
  32. public TreeNodeViewModel TreeNodeViewModel
  33. {
  34. get
  35. {
  36. return this.DataContext as TreeNodeViewModel;
  37. }
  38. set
  39. {
  40. this.DataContext = value;
  41. }
  42. }
  43. public void OnDataContextChange()
  44. {
  45. this.DataContext = this.nodeDataEditorViewModel.TreeNodeViewModel;
  46. }
  47. private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
  48. {
  49. if (this.TreeNodeViewModel == null)
  50. {
  51. return;
  52. }
  53. this.cbType.SelectedIndex = EnumHelper.EnumIndex<NodeType>(this.TreeNodeViewModel.Type);
  54. }
  55. private void CbType_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
  56. {
  57. if (this.TreeNodeViewModel == null)
  58. {
  59. return;
  60. }
  61. if (this.cbType.SelectedValue == null)
  62. {
  63. this.TreeNodeViewModel.Type = 0;
  64. return;
  65. }
  66. this.TreeNodeViewModel.Type =
  67. (int) Enum.Parse(typeof (NodeType), this.cbType.SelectedValue.ToString().Trim());
  68. }
  69. }
  70. }