123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using ComPDFKit.PDFDocument;
- using ComPDFKit.PDFDocument.Action;
- using compdfkit_tools.PDFControl;
- using compdfkit_tools.PDFView.PDFOutline.PDFOutlineData;
- using ComPDFKitViewer.PdfViewer;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace compdfkit_tools.PDFControlUI
- {
- public partial class CPDFOutlineNode
- {
- /// <summary>
- /// 大纲父节点
- /// </summary>
- public CPDFOutlineNode ParentNode = null;
- /// <summary>
- /// 当前大纲
- /// </summary>
- public CPDFOutline PDFOutline = null;
- /// <summary>
- /// 当前node名
- /// </summary>
- public string CurrentNodeName = string.Empty;
- /// <summary>
- /// 子大纲集合
- /// </summary>
- public ObservableCollection<CPDFOutlineNode> ChildrenNodeList
- {
- get;
- set;
- }
- /// <summary>
- /// 当前展开状态
- /// </summary>
- public bool IsExpanded = false;
- /// <summary>
- /// 当前节点页面
- /// </summary>
- public int PageIndex = 0;
- /// <summary>
- /// 当前节点所在页面中的水平位置
- /// </summary>
- public double PositionX;
- /// <summary>
- /// 当前节点所在页面中的垂直位置
- /// </summary>
- public double PositionY;
- }
- /// <summary>
- /// CPDFOutlineUI.xaml 的交互逻辑
- /// </summary>
- public partial class CPDFOutlineUI : UserControl, INotifyPropertyChanged
- {
- public event PropertyChangedEventHandler PropertyChanged;
- public ObservableCollection<CPDFOutlineNode> OutlineList { get; set; } = new ObservableCollection<CPDFOutlineNode>();
- public event EventHandler<object> OutlineSelectionChanged;
- public CPDFOutlineUI()
- {
- InitializeComponent();
- }
- private void BuildOutlineTree(List<CPDFOutline> outlineList, ItemCollection nodes)
- {
- foreach (var outline in outlineList)
- {
- TreeViewItem new_node = new TreeViewItem();
- new_node.Header = outline.Title;
- ToolTipService.SetToolTip(new_node, new_node.Header);
- nodes.Add(new_node);
- new_node.Tag = outline;
- List<CPDFOutline> childList = outline.ChildList;
- if (childList != null && childList.Count > 0)
- {
- BuildOutlineTree(childList, new_node.Items);
- }
- }
- }
- public void SetOutlineTree(List<CPDFOutline> outlineList)
- {
- this.OutlineList.Clear();
- if (!OutlineTree.HasItems)
- {
- if (outlineList != null && outlineList.Count > 0)
- {
- OutlineTree.BeginInit();
- BuildOutlineTree(outlineList, OutlineTree.Items);
- OutlineTree.EndInit();
- }
- }
- if(outlineList==null || outlineList.Count==0)
- {
- NoResultText.Visibility = Visibility.Visible;
- }
- else
- {
- NoResultText.Visibility= Visibility.Collapsed;
- }
- }
- private void OutlineTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- if (e.NewValue == null)
- {
- return;
- }
- OutlineSelectionChanged?.Invoke(this, e.NewValue);
- }
- }
- }
|