NodeDataEditor.xaml.cs 1.4 KB

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