using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;
namespace GeekDesk.Util.WrpaPanel
{
public abstract class VirtualizingPanelBase : VirtualizingPanel, IScrollInfo
{
public static readonly DependencyProperty ScrollLineDeltaProperty = DependencyProperty.Register(nameof(ScrollLineDelta), typeof(double), typeof(VirtualizingPanelBase), new FrameworkPropertyMetadata(16.0));
public static readonly DependencyProperty MouseWheelDeltaProperty = DependencyProperty.Register(nameof(MouseWheelDelta), typeof(double), typeof(VirtualizingPanelBase), new FrameworkPropertyMetadata(48.0));
public static readonly DependencyProperty ScrollLineDeltaItemProperty = DependencyProperty.Register(nameof(ScrollLineDeltaItem), typeof(int), typeof(VirtualizingPanelBase), new FrameworkPropertyMetadata(1));
public static readonly DependencyProperty MouseWheelDeltaItemProperty = DependencyProperty.Register(nameof(MouseWheelDeltaItem), typeof(int), typeof(VirtualizingPanelBase), new FrameworkPropertyMetadata(3));
public ScrollViewer? ScrollOwner { get; set; }
public bool CanVerticallyScroll { get; set; }
public bool CanHorizontallyScroll { get; set; }
protected override bool CanHierarchicallyScrollAndVirtualizeCore => true;
///
/// Scroll line delta for pixel based scrolling. The default value is 16 dp.
///
public double ScrollLineDelta { get => (double)GetValue(ScrollLineDeltaProperty); set => SetValue(ScrollLineDeltaProperty, value); }
///
/// Mouse wheel delta for pixel based scrolling. The default value is 48 dp.
///
public double MouseWheelDelta { get => (double)GetValue(MouseWheelDeltaProperty); set => SetValue(MouseWheelDeltaProperty, value); }
///
/// Scroll line delta for item based scrolling. The default value is 1 item.
///
public double ScrollLineDeltaItem { get => (int)GetValue(ScrollLineDeltaItemProperty); set => SetValue(ScrollLineDeltaItemProperty, value); }
///
/// Mouse wheel delta for item based scrolling. The default value is 3 items.
///
public int MouseWheelDeltaItem { get => (int)GetValue(MouseWheelDeltaItemProperty); set => SetValue(MouseWheelDeltaItemProperty, value); }
protected ScrollUnit ScrollUnit => GetScrollUnit(ItemsControl);
///
/// The direction in which the panel scrolls when user turns the mouse wheel.
///
protected ScrollDirection MouseWheelScrollDirection { get; set; } = ScrollDirection.Vertical;
protected bool IsVirtualizing => GetIsVirtualizing(ItemsControl);
protected VirtualizationMode VirtualizationMode => GetVirtualizationMode(ItemsControl);
///
/// Returns true if the panel is in VirtualizationMode.Recycling, otherwise false.
///
protected bool IsRecycling => VirtualizationMode == VirtualizationMode.Recycling;
///
/// The cache length before and after the viewport.
///
protected VirtualizationCacheLength CacheLength { get; private set; }
///
/// The Unit of the cache length. Can be Pixel, Item or Page.
/// When the ItemsOwner is a group item it can only be pixel or item.
///
protected VirtualizationCacheLengthUnit CacheLengthUnit { get; private set; }
///
/// The ItemsControl (e.g. ListView).
///
protected ItemsControl ItemsControl => ItemsControl.GetItemsOwner(this);
///
/// The ItemsControl (e.g. ListView) or if the ItemsControl is grouping a GroupItem.
///
protected DependencyObject ItemsOwner
{
get
{
if (_itemsOwner is null)
{
/* Use reflection to access internal method because the public
* GetItemsOwner method does always return the itmes control instead
* of the real items owner for example the group item when grouping */
MethodInfo getItemsOwnerInternalMethod = typeof(ItemsControl).GetMethod(
"GetItemsOwnerInternal",
BindingFlags.Static | BindingFlags.NonPublic,
null,
new Type[] { typeof(DependencyObject) },
null
)!;
_itemsOwner = (DependencyObject)getItemsOwnerInternalMethod.Invoke(null, new object[] { this })!;
}
return _itemsOwner;
}
}
private DependencyObject? _itemsOwner;
protected ReadOnlyCollection