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 { /// /// 缩略图列表点击选中事件 /// public event EventHandler SelectionChanged; /// /// 滚动状态改变事件 /// public event EventHandler ViewChanged; /// /// 缩略图结果列表 /// private List thumbResultList=new List(); public CPDFThumbnailUI() { InitializeComponent(); } /// /// 选中结果改变事件 /// private void ThumbListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { SelectionChanged?.Invoke(this, ThumbListBox.SelectedIndex); } /// /// 设置缩略图列表 /// /// public void SetThumbResult(List thumbList) { thumbResultList?.Clear(); ThumbListBox.ItemsSource = null; if (thumbList == null || thumbList.Count == 0) { return; } thumbResultList.AddRange(thumbList); ThumbListBox.ItemsSource = thumbResultList; } /// /// 内容滚动事件 /// private void ThumbListBox_ScrollChanged(object sender, ScrollChangedEventArgs e) { ViewChanged?.Invoke(this, e); } /// /// 判断指定对象是否可见 /// 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; } } /// /// 缩略图对象 /// public class ThumbnailItem { /// /// 图像宽度 /// public int ImageWidth { get; set; } /// /// 图像高度 /// public int ImageHeight { get; set; } /// ///缩略图宽度 /// public int ThumbnailWidth { get; set; } /// /// 缩略图高度 /// public int ThumbnailHeight { get; set; } /// /// 展示页码 /// public string ShowPageText { get { if (PageIndex >= 0) { return (PageIndex + 1).ToString(); } return string.Empty; } } /// /// 页面索引(以0开始) /// public int PageIndex { get; set; } = -1; /// /// 缩略图像内容 /// public Image ImageData { get; set; } = new Image(); } }