NodeDataEditor.xaml.cs 1.4 KB

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