using System; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media.Animation; namespace Gestor.Common.Helpers; public static class ScrollAnimationBehavior { public static DependencyProperty VerticalOffsetProperty = DependencyProperty.RegisterAttached("VerticalOffset", typeof(double), typeof(ScrollAnimationBehavior), (PropertyMetadata)new UIPropertyMetadata((object)0.0, new PropertyChangedCallback(OnVerticalOffsetChanged))); public static DependencyProperty TimeDurationProperty = DependencyProperty.RegisterAttached("TimeDuration", typeof(TimeSpan), typeof(ScrollAnimationBehavior), new PropertyMetadata((object)new TimeSpan(0, 0, 0, 0, 0))); public static DependencyProperty PointsToScrollProperty = DependencyProperty.RegisterAttached("PointsToScroll", typeof(double), typeof(ScrollAnimationBehavior), new PropertyMetadata((object)0.0)); public static DependencyProperty IsEnabledProperty = DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(ScrollAnimationBehavior), (PropertyMetadata)new UIPropertyMetadata((object)false, new PropertyChangedCallback(OnIsEnabledChanged))); private static double _currentToValue; private static Storyboard _storyboard; public static void SetTimeDuration(FrameworkElement target, TimeSpan value) { ((DependencyObject)target).SetValue(TimeDurationProperty, (object)value); } public static TimeSpan GetTimeDuration(FrameworkElement target) { return (TimeSpan)((DependencyObject)target).GetValue(TimeDurationProperty); } public static void SetPointsToScroll(FrameworkElement target, double value) { ((DependencyObject)target).SetValue(PointsToScrollProperty, (object)value); } private static void OnVerticalOffsetChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) { ScrollViewer val = (ScrollViewer)(object)((target is ScrollViewer) ? target : null); if (val != null) { val.ScrollToVerticalOffset((double)e.NewValue); } } public static void SetIsEnabled(FrameworkElement target, bool value) { ((DependencyObject)target).SetValue(IsEnabledProperty, (object)value); } private static void OnIsEnabledChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown ScrollViewer val = (ScrollViewer)(object)((sender is ScrollViewer) ? sender : null); if (val != null) { ((FrameworkElement)val).Loaded += new RoutedEventHandler(ScrollerLoaded); } } private static void AnimateScroll(ScrollViewer scrollViewer) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown DoubleAnimationUsingKeyFrames val = new DoubleAnimationUsingKeyFrames { Duration = new Duration(GetTimeDuration((FrameworkElement)(object)scrollViewer)) }; val.KeyFrames.Add((DoubleKeyFrame)new EasingDoubleKeyFrame(scrollViewer.VerticalOffset, KeyTime.FromPercent(0.0))); val.KeyFrames.Add((DoubleKeyFrame)new EasingDoubleKeyFrame(_currentToValue, KeyTime.FromPercent(1.0), (IEasingFunction)new SineEase { EasingMode = (EasingMode)1 })); _storyboard = new Storyboard(); ((TimelineGroup)_storyboard).Children.Add((Timeline)(object)val); Storyboard.SetTarget((DependencyObject)(object)val, (DependencyObject)(object)scrollViewer); Storyboard.SetTargetProperty((DependencyObject)(object)val, new PropertyPath((object)VerticalOffsetProperty)); _storyboard.Begin(); } private static void SetEventHandlersForScrollViewer(ScrollViewer scroller) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown ((UIElement)scroller).PreviewMouseWheel += new MouseWheelEventHandler(ScrollViewerPreviewMouseWheel); } private static void ScrollerLoaded(object sender, RoutedEventArgs e) { SetEventHandlersForScrollViewer((ScrollViewer)((sender is ScrollViewer) ? sender : null)); } private static void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs e) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Invalid comparison between Unknown and I4 double currentToValue = _currentToValue; double num = e.Delta; ScrollViewer val = (ScrollViewer)sender; double num2 = num * 2.0 / 3.0; if (_storyboard == null || (int)_storyboard.GetCurrentState() == 1) { _currentToValue = val.VerticalOffset; } _currentToValue = ((num2 > _currentToValue) ? 0.0 : ((_currentToValue - num2 > val.ScrollableHeight) ? val.ScrollableHeight : (_currentToValue - num2))); if (_currentToValue != val.VerticalOffset && _currentToValue != currentToValue) { AnimateScroll(val); } ((RoutedEventArgs)e).Handled = true; } }