NodeDataEditor.xaml.cs 1.6 KB

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