ObjectInTreeView.xaml.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System.Collections.Generic;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. namespace MECF.Framework.UI.Core.ExtendedControls
  5. {
  6. /// <summary>
  7. /// ObjectInTreeView.xaml 的交互逻辑
  8. /// </summary>
  9. public partial class ObjectInTreeView : UserControl
  10. {
  11. public ObjectInTreeView()
  12. {
  13. InitializeComponent();
  14. }
  15. public object ObjectToVisualize
  16. {
  17. get { return (object) GetValue(ObjectToVisualizeProperty); }
  18. set { SetValue(ObjectToVisualizeProperty, value); }
  19. }
  20. public static readonly DependencyProperty ObjectToVisualizeProperty =
  21. DependencyProperty.Register("ObjectToVisualize", typeof(object), typeof(ObjectInTreeView),
  22. new PropertyMetadata(null, OnObjectChanged));
  23. private static void OnObjectChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  24. {
  25. ObjectTreeNode tree = ObjectTreeNode.CreateTree(e.NewValue);
  26. (d as ObjectInTreeView).TreeNodes = new List<ObjectTreeNode>() {tree};
  27. }
  28. public List<ObjectTreeNode> TreeNodes
  29. {
  30. get { return (List<ObjectTreeNode>) GetValue(TreeNodesProperty); }
  31. set { SetValue(TreeNodesProperty, value); }
  32. }
  33. public static readonly DependencyProperty TreeNodesProperty =
  34. DependencyProperty.Register("TreeNodes", typeof(List<ObjectTreeNode>), typeof(ObjectInTreeView),
  35. new PropertyMetadata(null));
  36. }
  37. }