CPDFOutlineUI.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using ComPDFKit.PDFDocument;
  2. using compdfkit_tools.PDFControl;
  3. using compdfkit_tools.PDFView.PDFOutline.PDFOutlineData;
  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 CPDFOutlineUI()
  70. {
  71. InitializeComponent();
  72. }
  73. private void BuildOutlineTree(List<CPDFOutline> outlineList, ItemCollection nodes)
  74. {
  75. foreach (var outline in outlineList)
  76. {
  77. TreeViewItem new_node = new TreeViewItem();
  78. new_node.Header = outline.Title;
  79. ToolTipService.SetToolTip(new_node, new_node.Header);
  80. nodes.Add(new_node);
  81. new_node.Tag = outline;
  82. List<CPDFOutline> childList = outline.ChildList;
  83. if (childList != null && childList.Count > 0)
  84. {
  85. BuildOutlineTree(childList, new_node.Items);
  86. }
  87. }
  88. }
  89. public void SetOutlineTree(List<CPDFOutline> outlineList)
  90. {
  91. this.OutlineList.Clear();
  92. if (!OutlineTree.HasItems)
  93. {
  94. //OutlineTree.FontSize = 14;
  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. }
  112. }