NodeDataEditor.xaml.cs 1.5 KB

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