CPDFOutlineUI.xaml.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using ComPDFKit.PDFDocument;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.ComponentModel;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. namespace ComPDFKit.Controls.PDFControlUI
  9. {
  10. public partial class CPDFOutlineNode
  11. {
  12. public CPDFOutlineNode ParentNode = null;
  13. public CPDFOutline PDFOutline = null;
  14. public string CurrentNodeName = string.Empty;
  15. public ObservableCollection<CPDFOutlineNode> ChildrenNodeList
  16. {
  17. get;
  18. set;
  19. }
  20. public bool IsExpanded = false;
  21. public int PageIndex = 0;
  22. public double PositionX;
  23. public double PositionY;
  24. }
  25. public partial class CPDFOutlineUI : UserControl, INotifyPropertyChanged
  26. {
  27. public event PropertyChangedEventHandler PropertyChanged;
  28. public ObservableCollection<CPDFOutlineNode> OutlineList { get; set; } = new ObservableCollection<CPDFOutlineNode>();
  29. public event EventHandler<object> OutlineSelectionChanged;
  30. public CPDFOutlineUI()
  31. {
  32. InitializeComponent();
  33. }
  34. private void BuildOutlineTree(List<CPDFOutline> outlineList, ItemCollection nodes)
  35. {
  36. foreach (var outline in outlineList)
  37. {
  38. TreeViewItem new_node = new TreeViewItem();
  39. new_node.Header = outline.Title;
  40. ToolTipService.SetToolTip(new_node, new_node.Header);
  41. nodes.Add(new_node);
  42. new_node.Tag = outline;
  43. List<CPDFOutline> childList = outline.ChildList;
  44. if (childList != null && childList.Count > 0)
  45. {
  46. BuildOutlineTree(childList, new_node.Items);
  47. }
  48. }
  49. }
  50. public void SetOutlineTree(List<CPDFOutline> outlineList)
  51. {
  52. this.OutlineList.Clear();
  53. if (!OutlineTree.HasItems)
  54. {
  55. if (outlineList != null && outlineList.Count > 0)
  56. {
  57. OutlineTree.BeginInit();
  58. BuildOutlineTree(outlineList, OutlineTree.Items);
  59. OutlineTree.EndInit();
  60. }
  61. }
  62. if(outlineList==null || outlineList.Count==0)
  63. {
  64. NoResultText.Visibility = Visibility.Visible;
  65. }
  66. else
  67. {
  68. NoResultText.Visibility= Visibility.Collapsed;
  69. }
  70. }
  71. private void OutlineTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  72. {
  73. if (e.NewValue == null)
  74. {
  75. return;
  76. }
  77. OutlineSelectionChanged?.Invoke(this, e.NewValue);
  78. }
  79. }
  80. }