summaryrefslogtreecommitdiff
path: root/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs
blob: 3af3b0d679f087930abd9b4a7e59c4f96c54a594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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;
	}
}