CPDFOutlineUI.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFDocument.Action;
  3. using Compdfkit_Tools.PDFControl;
  4. using ComPDFKitViewer.PdfViewer;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.ComponentModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. namespace Compdfkit_Tools.PDFControlUI
  22. {
  23. public partial class CPDFOutlineNode
  24. {
  25. /// <summary>
  26. /// 大纲父节点
  27. /// </summary>
  28. public CPDFOutlineNode ParentNode = null;
  29. /// <summary>
  30. /// 当前大纲
  31. /// </summary>
  32. public CPDFOutline PDFOutline = null;
  33. /// <summary>
  34. /// 当前node名
  35. /// </summary>
  36. public string CurrentNodeName = string.Empty;
  37. /// <summary>
  38. /// 子大纲集合
  39. /// </summary>
  40. public ObservableCollection<CPDFOutlineNode> ChildrenNodeList
  41. {
  42. get;
  43. set;
  44. }
  45. /// <summary>
  46. /// 当前展开状态
  47. /// </summary>
  48. public bool IsExpanded = false;
  49. /// <summary>
  50. /// 当前节点页面
  51. /// </summary>
  52. public int PageIndex = 0;
  53. /// <summary>
  54. /// 当前节点所在页面中的水平位置
  55. /// </summary>
  56. public double PositionX;
  57. /// <summary>
  58. /// 当前节点所在页面中的垂直位置
  59. /// </summary>
  60. public double PositionY;
  61. }
  62. /// <summary>
  63. /// CPDFOutlineUI.xaml 的交互逻辑
  64. /// </summary>
  65. public partial class CPDFOutlineUI : UserControl, INotifyPropertyChanged
  66. {
  67. public event PropertyChangedEventHandler PropertyChanged;
  68. public ObservableCollection<CPDFOutlineNode> OutlineList { get; set; } = new ObservableCollection<CPDFOutlineNode>();
  69. public event EventHandler<object> OutlineSelectionChanged;
  70. public CPDFOutlineUI()
  71. {
  72. InitializeComponent();
  73. }
  74. private void BuildOutlineTree(List<CPDFOutline> outlineList, ItemCollection nodes)
  75. {
  76. foreach (var outline in outlineList)
  77. {
  78. TreeViewItem new_node = new TreeViewItem();
  79. new_node.Header = outline.Title;
  80. ToolTipService.SetToolTip(new_node, new_node.Header);
  81. nodes.Add(new_node);
  82. new_node.Tag = outline;
  83. List<CPDFOutline> childList = outline.ChildList;
  84. if (childList != null && childList.Count > 0)
  85. {
  86. BuildOutlineTree(childList, new_node.Items);
  87. }
  88. }
  89. }
  90. public void SetOutlineTree(List<CPDFOutline> outlineList)
  91. {
  92. this.OutlineList.Clear();
  93. if (!OutlineTree.HasItems)
  94. {
  95. if (outlineList != null && outlineList.Count > 0)
  96. {
  97. OutlineTree.BeginInit();
  98. BuildOutlineTree(outlineList, OutlineTree.Items);
  99. OutlineTree.EndInit();
  100. }
  101. }
  102. if(outlineList==null || outlineList.Count==0)
  103. {
  104. NoResultText.Visibility = Visibility.Visible;
  105. }
  106. else
  107. {
  108. NoResultText.Visibility= Visibility.Collapsed;
  109. }
  110. }
  111. private void OutlineTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  112. {
  113. if (e.NewValue == null)
  114. {
  115. return;
  116. }
  117. OutlineSelectionChanged?.Invoke(this, e.NewValue);
  118. }
  119. }
  120. }