NodeDataEditor.xaml.cs 1.4 KB

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