123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System;
- using System.Numerics;
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Controls.Presenters;
- using Avalonia.Controls.Primitives;
- using Avalonia.Rendering.Composition;
- using Avalonia.Rendering.Composition.Animations;
- namespace SukiUI.Theme
- {
- public static class Scrollable
- {
- public static void MakeScrollable(CompositionVisual compositionVisual)
- {
- if (compositionVisual == null)
- return;
-
- Compositor compositor = compositionVisual.Compositor;
- var animationGroup = compositor.CreateAnimationGroup();
- Vector3KeyFrameAnimation offsetAnimation = compositor.CreateVector3KeyFrameAnimation();
- offsetAnimation.Target = "Offset";
- offsetAnimation.InsertExpressionKeyFrame(1.0f, "this.FinalValue");
- offsetAnimation.Duration = TimeSpan.FromMilliseconds(250);
- ImplicitAnimationCollection implicitAnimationCollection = compositor.CreateImplicitAnimationCollection();
- animationGroup.Add(offsetAnimation);
- implicitAnimationCollection["Offset"] = animationGroup;
- compositionVisual.ImplicitAnimations = implicitAnimationCollection;
- }
-
-
- }
-
-
-
-
- public static class StackPanelExtensions
- {
- public static readonly AttachedProperty<bool> AnimatedScrollProperty =
- AvaloniaProperty.RegisterAttached<StackPanel, bool>("AnimatedScroll", typeof(StackPanel), defaultValue: false);
- static StackPanelExtensions()
- {
- AnimatedScrollProperty.Changed.AddClassHandler<StackPanel>(HandleAnimatedScrollChanged);
- }
-
- private static void HandleAnimatedScrollChanged(StackPanel interactElem, AvaloniaPropertyChangedEventArgs args)
- {
- if(GetAnimatedScroll(interactElem))
- interactElem.AttachedToVisualTree += (sender, args) => Scrollable.MakeScrollable(ElementComposition.GetElementVisual(interactElem));
- }
- public static bool GetAnimatedScroll(StackPanel wrap)
- {
- return wrap.GetValue(AnimatedScrollProperty);
- }
- public static void SetAnimatedScroll(StackPanel wrap, bool value)
- {
- wrap.SetValue(AnimatedScrollProperty, value);
- }
- }
-
- public static class WrapPanelExtensions
- {
- public static readonly AttachedProperty<bool> AnimatedScrollProperty =
- AvaloniaProperty.RegisterAttached<WrapPanel, bool>("AnimatedScroll", typeof(WrapPanel), defaultValue: false);
- static WrapPanelExtensions()
- {
- AnimatedScrollProperty.Changed.AddClassHandler<WrapPanel>(HandleAnimatedScrollChanged);
- }
-
- private static void HandleAnimatedScrollChanged(WrapPanel interactElem, AvaloniaPropertyChangedEventArgs args)
- {
- if(GetAnimatedScroll(interactElem))
- interactElem.AttachedToVisualTree += (sender, args) => Scrollable.MakeScrollable(ElementComposition.GetElementVisual(interactElem));
- }
- public static bool GetAnimatedScroll(WrapPanel wrap)
- {
- return wrap.GetValue(AnimatedScrollProperty);
- }
- public static void SetAnimatedScroll(WrapPanel wrap, bool value)
- {
- wrap.SetValue(AnimatedScrollProperty, value);
- }
- }
-
- public static class ItemsPresenterExtensions
- {
- public static readonly AttachedProperty<bool> AnimatedScrollProperty =
- AvaloniaProperty.RegisterAttached<ItemsPresenter, bool>("AnimatedScroll", typeof(ItemsPresenter), defaultValue: false);
- static ItemsPresenterExtensions()
- {
- AnimatedScrollProperty.Changed.AddClassHandler<ItemsPresenter>(HandleAnimatedScrollChanged);
- }
-
- private static void HandleAnimatedScrollChanged(ItemsPresenter interactElem, AvaloniaPropertyChangedEventArgs args)
- {
- if(GetAnimatedScroll(interactElem))
- interactElem.AttachedToVisualTree += (sender, args) => Scrollable.MakeScrollable(ElementComposition.GetElementVisual(interactElem));
- }
- public static bool GetAnimatedScroll(ItemsPresenter wrap)
- {
- return wrap.GetValue(AnimatedScrollProperty);
- }
- public static void SetAnimatedScroll(ItemsPresenter wrap, bool value)
- {
- wrap.SetValue(AnimatedScrollProperty, value);
- }
- }
-
- public static class ItemsControlExtensions
- {
- public static readonly AttachedProperty<bool> AnimatedScrollProperty =
- AvaloniaProperty.RegisterAttached<ItemsControl, bool>("AnimatedScroll", typeof(ItemsControl), defaultValue: false);
- static ItemsControlExtensions()
- {
- AnimatedScrollProperty.Changed.AddClassHandler<ItemsControl>(HandleAnimatedScrollChanged);
- }
-
- private static void HandleAnimatedScrollChanged(ItemsControl interactElem, AvaloniaPropertyChangedEventArgs args)
- {
- if(GetAnimatedScroll(interactElem))
- interactElem.AttachedToVisualTree += (sender, args) => Scrollable.MakeScrollable(ElementComposition.GetElementVisual(interactElem));
- }
- public static bool GetAnimatedScroll(ItemsControl wrap)
- {
- return wrap.GetValue(AnimatedScrollProperty);
- }
- public static void SetAnimatedScroll(ItemsControl wrap, bool value)
- {
- wrap.SetValue(AnimatedScrollProperty, value);
- }
- }
-
-
- }
|