CPDFOutlineUI.xaml.cs 3.9 KB

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