123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- 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;
- using System.Xml.Linq;
- namespace compdfkit_tools.PDFControlUI
- {
- public partial class CPDFThumbnailUI : UserControl
- {
- /// <summary>
- /// 缩略图列表点击选中事件
- /// </summary>
- public event EventHandler<int> SelectionChanged;
- /// <summary>
- /// 滚动状态改变事件
- /// </summary>
- public event EventHandler<ScrollChangedEventArgs> ViewChanged;
- /// <summary>
- /// 缩略图结果列表
- /// </summary>
- private List<ThumbnailItem> thumbResultList=new List<ThumbnailItem>();
- public CPDFThumbnailUI()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 选中结果改变事件
- /// </summary>
- private void ThumbListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- SelectionChanged?.Invoke(this, ThumbListBox.SelectedIndex);
- }
- /// <summary>
- /// 设置缩略图列表
- /// </summary>
- /// <param name="thumbList"></param>
- public void SetThumbResult(List<ThumbnailItem> thumbList)
- {
- thumbResultList?.Clear();
- ThumbListBox.ItemsSource = null;
- if (thumbList == null || thumbList.Count == 0)
- {
- return;
- }
- thumbResultList.AddRange(thumbList);
- ThumbListBox.ItemsSource = thumbResultList;
- }
- /// <summary>
- /// 内容滚动事件
- /// </summary>
- private void ThumbListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
- {
- ViewChanged?.Invoke(this, e);
- }
- /// <summary>
- /// 判断指定对象是否可见
- /// </summary>
- public bool IsItemVisible(ThumbnailItem checkItem)
- {
- if (ThumbListBox == null || thumbResultList == null || thumbResultList.Count == 0)
- {
- return false;
- }
- try
- {
- int index = thumbResultList.IndexOf(checkItem);
- if (index != -1)
- {
- ListBoxItem itemContainer = (ListBoxItem)ThumbListBox.ItemContainerGenerator.ContainerFromIndex(index);
- if (itemContainer==null || itemContainer.IsVisible == false || itemContainer.Visibility != Visibility.Visible)
- {
- return false;
- }
- GeneralTransform transform = itemContainer.TransformToAncestor(ThumbListBox);
- Rect visualRect= transform.TransformBounds(new Rect(
- 0,
- 0,
- itemContainer.ActualWidth,
- itemContainer.ActualHeight
- ));
- Rect containerRect=new Rect(
- 0,
- 0,
- ThumbListBox.ActualWidth,
- ThumbListBox.ActualHeight);
- if (containerRect.IntersectsWith(visualRect))
- {
- return true;
- }
- }
- }
- catch(Exception ex)
- {
- }
-
- return false;
- }
- }
- /// <summary>
- /// 缩略图对象
- /// </summary>
- public class ThumbnailItem
- {
- /// <summary>
- /// 图像宽度
- /// </summary>
- public int ImageWidth { get; set; }
- /// <summary>
- /// 图像高度
- /// </summary>
- public int ImageHeight { get; set; }
- /// <summary>
- ///缩略图宽度
- /// </summary>
- public int ThumbnailWidth { get; set; }
- /// <summary>
- /// 缩略图高度
- /// </summary>
- public int ThumbnailHeight { get; set; }
- /// <summary>
- /// 展示页码
- /// </summary>
- public string ShowPageText
- {
- get
- {
- if (PageIndex >= 0)
- {
- return (PageIndex + 1).ToString();
- }
- return string.Empty;
- }
- }
- /// <summary>
- /// 页面索引(以0开始)
- /// </summary>
- public int PageIndex { get; set; } = -1;
- /// <summary>
- /// 缩略图像内容
- /// </summary>
- public Image ImageData { get; set; } = new Image();
- }
- }
|