From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Gestor.Common.Helpers/DataBaseParameters.cs | 14 ++ .../Gestor.Common.Helpers/DefaultAttribute.cs | 19 +++ .../Gestor.Common.Helpers/EncryptionHelper.cs | 106 +++++++++++++ .../EnumBindingSourceExtension.cs | 59 ++++++++ .../Gestor.Common.Helpers/EnumHelper.cs | 166 +++++++++++++++++++++ .../Gestor.Common.Helpers/FindVisualChild.cs | 32 ++++ .../Gestor.Common.Helpers/FindVisualChildren.cs | 38 +++++ .../Gestor.Common.Helpers/Functions.cs | 110 ++++++++++++++ .../Gestor.Common.Helpers/HiddenAttribute.cs | 12 ++ .../Gestor.Common.Helpers/HttpHelper.cs | 25 ++++ .../Gestor.Common.Helpers/OrderAttribute.cs | 20 +++ .../ScrollAnimationBehavior.cs | 124 +++++++++++++++ 12 files changed, 725 insertions(+) create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/Functions.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs create mode 100644 Codemerx/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs (limited to 'Codemerx/Gestor.Common/Gestor.Common.Helpers') diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs new file mode 100644 index 0000000..03ccc65 --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs @@ -0,0 +1,14 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Gestor.Common.Helpers +{ + public static class DataBaseParameters + { + public static bool NovoGestor + { + get; + set; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs new file mode 100644 index 0000000..b79d623 --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs @@ -0,0 +1,19 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Gestor.Common.Helpers +{ + public class DefaultAttribute : Attribute + { + public bool DefaultProperty + { + get; + private set; + } + + public DefaultAttribute(bool defaultProperty) + { + this.DefaultProperty = defaultProperty; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs new file mode 100644 index 0000000..b2102d2 --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs @@ -0,0 +1,106 @@ +using System; +using System.IO; +using System.Runtime.CompilerServices; +using System.Security.Cryptography; +using System.Text; + +namespace Gestor.Common.Helpers +{ + public static class EncryptionHelper + { + private readonly static byte[] Salt; + + private readonly static string EncryptionKey; + + static EncryptionHelper() + { + EncryptionHelper.Salt = new byte[] { 38, 220, 255, 0, 173, 237, 122, 238, 197, 254, 7, 175, 77, 8, 34, 60 }; + EncryptionHelper.EncryptionKey = string.Format("aGG3r{0}#w3BDz$", 1012); + } + + public static string Decrypt(this string cipher) + { + string str; + if (string.IsNullOrEmpty(cipher)) + { + return null; + } + try + { + byte[] numArray = Convert.FromBase64String(cipher); + if ((int)numArray.Length >= 16) + { + byte[] numArray1 = numArray.DecryptBytes(); + str = (numArray1 == null ? cipher : Encoding.UTF8.GetString(numArray1)); + } + else + { + str = cipher; + } + } + catch (Exception exception) + { + str = cipher; + } + return str; + } + + public static byte[] DecryptBytes(this byte[] plainTextBytes) + { + byte[] array; + try + { + using (Rfc2898DeriveBytes rfc2898DeriveByte = new Rfc2898DeriveBytes(EncryptionHelper.EncryptionKey, EncryptionHelper.Salt)) + { + using (Rijndael bytes = Rijndael.Create()) + { + bytes.Key = rfc2898DeriveByte.GetBytes(32); + bytes.IV = rfc2898DeriveByte.GetBytes(16); + using (MemoryStream memoryStream = new MemoryStream()) + { + using (CryptoStream cryptoStream = new CryptoStream(memoryStream, bytes.CreateDecryptor(), CryptoStreamMode.Write)) + { + cryptoStream.Write(plainTextBytes, 0, (int)plainTextBytes.Length); + cryptoStream.FlushFinalBlock(); + array = memoryStream.ToArray(); + } + } + } + } + } + catch (Exception exception) + { + array = null; + } + return array; + } + + public static string Encrypt(this string plain) + { + return Convert.ToBase64String(Encoding.UTF8.GetBytes(plain).EncryptBytes()); + } + + public static byte[] EncryptBytes(this byte[] plainTextBytes) + { + byte[] array; + using (Rfc2898DeriveBytes rfc2898DeriveByte = new Rfc2898DeriveBytes(EncryptionHelper.EncryptionKey, EncryptionHelper.Salt)) + { + using (Rijndael bytes = Rijndael.Create()) + { + bytes.Key = rfc2898DeriveByte.GetBytes(32); + bytes.IV = rfc2898DeriveByte.GetBytes(16); + using (MemoryStream memoryStream = new MemoryStream()) + { + using (CryptoStream cryptoStream = new CryptoStream(memoryStream, bytes.CreateEncryptor(), CryptoStreamMode.Write)) + { + cryptoStream.Write(plainTextBytes, 0, (int)plainTextBytes.Length); + cryptoStream.FlushFinalBlock(); + array = memoryStream.ToArray(); + } + } + } + } + return array; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs new file mode 100644 index 0000000..7ce699e --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs @@ -0,0 +1,59 @@ +using System; +using System.Windows.Markup; + +namespace Gestor.Common.Helpers +{ + public class EnumBindingSourceExtension : MarkupExtension + { + private Type _enumType; + + public Type EnumType + { + get + { + return this._enumType; + } + set + { + if (value == this._enumType) + { + return; + } + if (null != value) + { + if (!(Nullable.GetUnderlyingType(value) ?? value).IsEnum) + { + throw new ArgumentException("Type must be for an Enum."); + } + } + this._enumType = value; + } + } + + public EnumBindingSourceExtension() + { + } + + public EnumBindingSourceExtension(Type enumType) + { + this.EnumType = enumType; + } + + public override object ProvideValue(IServiceProvider serviceProvider) + { + if (null == this._enumType) + { + throw new InvalidOperationException("The EnumType must be specified."); + } + Type underlyingType = Nullable.GetUnderlyingType(this._enumType) ?? this._enumType; + Array values = Enum.GetValues(underlyingType); + if (underlyingType == this._enumType) + { + return values; + } + Array arrays = Array.CreateInstance(underlyingType, values.Length + 1); + values.CopyTo(arrays, 1); + return arrays; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs new file mode 100644 index 0000000..33529b8 --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs @@ -0,0 +1,166 @@ +using Gestor.Model.Attributes; +using System; +using System.ComponentModel; +using System.Reflection; +using System.Runtime.CompilerServices; + +namespace Gestor.Common.Helpers +{ + public static class EnumHelper + { + public static T2 GetAttribute(this T enumValue) + where T2 : class + { + T2 customAttribute; + string name = Enum.GetName(enumValue.GetType(), enumValue); + try + { + customAttribute = (T2)(Attribute.GetCustomAttribute(enumValue.GetType().GetField(name), typeof(T2)) as T2); + } + catch (Exception exception) + { + customAttribute = default(T2); + } + return customAttribute; + } + + public static bool? GetDefault(this T enumValue) + { + object customAttribute; + string name = Enum.GetName(enumValue.GetType(), enumValue); + FieldInfo field = enumValue.GetType().GetField(name); + if (field == null) + { + customAttribute = null; + } + else + { + customAttribute = Attribute.GetCustomAttribute(field, typeof(DefaultAttribute)) as DefaultAttribute; + } + if (customAttribute != null) + { + return new bool?(((DefaultAttribute)customAttribute).DefaultProperty); + } + return null; + } + + public static string GetDescription(this T enumValue) + { + object customAttribute; + string name = Enum.GetName(enumValue.GetType(), enumValue); + if (name == null) + { + return null; + } + FieldInfo field = enumValue.GetType().GetField(name); + if (field == null) + { + customAttribute = null; + } + else + { + customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute; + } + if (customAttribute != null) + { + return ((DescriptionAttribute)customAttribute).Description; + } + return null; + } + + public static bool GetHidden(this T enumValue) + { + object customAttribute; + string name = Enum.GetName(enumValue.GetType(), enumValue); + FieldInfo field = enumValue.GetType().GetField(name); + if (field == null) + { + customAttribute = null; + } + else + { + customAttribute = Attribute.GetCustomAttribute(field, typeof(HiddenAttribute)) as HiddenAttribute; + } + return customAttribute != null; + } + + public static string GetOldValue(this T enumValue) + { + OldValueAttribute attribute = enumValue.GetAttribute(); + if (attribute != null) + { + return attribute.OldValue; + } + return null; + } + + public static string GetOldValue2(this T enumValue) + { + OldValue2Attribute attribute = enumValue.GetAttribute(); + if (attribute != null) + { + return attribute.OldValue2; + } + return null; + } + + public static int? GetOrder(this T enumValue) + { + object customAttribute; + string name = Enum.GetName(enumValue.GetType(), enumValue); + FieldInfo field = enumValue.GetType().GetField(name); + if (field == null) + { + customAttribute = null; + } + else + { + customAttribute = Attribute.GetCustomAttribute(field, typeof(OrderAttribute)) as OrderAttribute; + } + if (customAttribute != null) + { + return new int?(((OrderAttribute)customAttribute).OrderProperty); + } + return null; + } + + public static T ToEnumByOldValue(this string oldValue) + { + Type type = typeof(T); + Type type1 = typeof(OldValueAttribute); + FieldInfo[] fields = type.GetFields(); + for (int i = 0; i < (int)fields.Length; i++) + { + FieldInfo fieldInfo = fields[i]; + OldValueAttribute customAttribute = Attribute.GetCustomAttribute(fieldInfo, type1) as OldValueAttribute; + if (customAttribute != null && customAttribute.OldValue == oldValue) + { + return (T)fieldInfo.GetValue(null); + } + } + return default(T); + } + + public static T ToEnumByOldValue2(this string oldValue) + { + Type type = typeof(T); + Type type1 = typeof(OldValue2Attribute); + FieldInfo[] fields = type.GetFields(); + for (int i = 0; i < (int)fields.Length; i++) + { + FieldInfo fieldInfo = fields[i]; + OldValue2Attribute customAttribute = Attribute.GetCustomAttribute(fieldInfo, type1) as OldValue2Attribute; + if (customAttribute != null && customAttribute.OldValue2 == oldValue) + { + return (T)fieldInfo.GetValue(null); + } + } + return default(T); + } + + public static string Value(this T enumValue) + { + return Convert.ToInt32(enumValue).ToString(); + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs new file mode 100644 index 0000000..4cabf7c --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs @@ -0,0 +1,32 @@ +using System; +using System.Windows; +using System.Windows.Media; + +namespace Gestor.Common.Helpers +{ + public class FindVisualChild + { + public FindVisualChild() + { + } + + public static childItem Find(DependencyObject obj) + where childItem : DependencyObject + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) + { + DependencyObject child = VisualTreeHelper.GetChild(obj, i); + if (child != null && child is childItem) + { + return (childItem)child; + } + childItem _childItem = FindVisualChild.Find(child); + if (_childItem != null) + { + return _childItem; + } + } + return default(childItem); + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs new file mode 100644 index 0000000..9b7f11d --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Windows; +using System.Windows.Media; + +namespace Gestor.Common.Helpers +{ + public class FindVisualChildren + { + public FindVisualChildren() + { + } + + public static IEnumerable Find(DependencyObject depObj) + where T : DependencyObject + { + if (depObj != null) + { + for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++) + { + DependencyObject dependencyObject = VisualTreeHelper.GetChild(depObj, i); + if (dependencyObject != null && dependencyObject is T) + { + yield return (T)dependencyObject; + } + foreach (T t in FindVisualChildren.Find(dependencyObject)) + { + yield return t; + } + dependencyObject = null; + } + } + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/Functions.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/Functions.cs new file mode 100644 index 0000000..25ffadf --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/Functions.cs @@ -0,0 +1,110 @@ +using Gestor.Common.Validation; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Runtime.CompilerServices; + +namespace Gestor.Common.Helpers +{ + public class Functions + { + public static System.Diagnostics.Stopwatch Stopwatch; + + public static DateTime? StartTime; + + public Functions() + { + } + + public static int Compare(string original, string modified) + { + if (original == null) + { + original = ""; + } + if (modified == null) + { + modified = ""; + } + string str = original.ToLongNullable().ToString(); + if (!string.IsNullOrWhiteSpace(str)) + { + original = str; + } + str = modified.ToLongNullable().ToString(); + if (!string.IsNullOrWhiteSpace(str)) + { + modified = str; + } + int length = original.Length; + int num = modified.Length; + int[,] numArray = new int[length + 1, num + 1]; + for (int i = 0; i <= length; i++) + { + numArray[i, 0] = i; + } + for (int j = 0; j <= num; j++) + { + numArray[0, j] = j; + } + for (int k = 1; k <= length; k++) + { + for (int l = 1; l <= num; l++) + { + int num1 = modified[l - 1] != original[k - 1]; + numArray[k, l] = (new int[] { numArray[k - 1, l] + 1, numArray[k, l - 1] + 1, numArray[k - 1, l - 1] + num1 }).Min(); + if (k > 1 && l > 1 && original[k - 1] == modified[l - 2] && original[k - 2] == modified[l - 1]) + { + numArray[k, l] = Math.Min(numArray[k, l], numArray[k - 2, l - 2] + num1); + } + } + } + return numArray[length, num]; + } + + public static DateTime GetNetworkTime() + { + DateTime value; + try + { + if (!Functions.StartTime.HasValue) + { + byte[] numArray = new byte[48]; + numArray[0] = 27; + IPEndPoint pEndPoint = new IPEndPoint(((IEnumerable)Dns.GetHostEntry("time.google.com").AddressList).First((IPAddress a) => a.AddressFamily == AddressFamily.InterNetwork), 123); + using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) + { + socket.Connect(pEndPoint); + socket.ReceiveTimeout = 3000; + socket.Send(numArray); + socket.Receive(numArray); + socket.Close(); + } + ulong num = (ulong)numArray[40] << 24 | (ulong)numArray[41] << 16 | (ulong)numArray[42] << 8 | (ulong)numArray[43]; + ulong num1 = (ulong)numArray[44] << 24 | (ulong)numArray[45] << 16 | (ulong)numArray[46] << 8 | (ulong)numArray[47]; + ulong num2 = num * (long)1000 + num1 * (long)1000 / 4294967296L; + DateTime dateTime = new DateTime(1900, 1, 1); + dateTime = dateTime.AddMilliseconds((double)num2); + Functions.StartTime = new DateTime?(dateTime.ToLocalTime()); + Functions.Stopwatch = System.Diagnostics.Stopwatch.StartNew(); + value = Functions.StartTime.Value; + } + else + { + value = Functions.StartTime.Value; + value = value.AddMilliseconds((double)Functions.Stopwatch.ElapsedMilliseconds); + } + } + catch (Exception exception) + { + Functions.StartTime = new DateTime?(DateTime.Now); + Functions.Stopwatch = System.Diagnostics.Stopwatch.StartNew(); + value = Functions.StartTime.Value; + } + return value; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs new file mode 100644 index 0000000..236be6f --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Gestor.Common.Helpers +{ + [AttributeUsage(AttributeTargets.All)] + public class HiddenAttribute : Attribute + { + public HiddenAttribute() + { + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs new file mode 100644 index 0000000..26b53e3 --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Runtime.CompilerServices; + +namespace Gestor.Common.Helpers +{ + public static class HttpHelper + { + public static HttpRequestMessage CreateRequest(this Uri requestUri, HttpMethod httpMethod, Version httpVersion = null) + { + HttpRequestMessage httpRequestMessage = new HttpRequestMessage(); + httpRequestMessage.set_Version(httpVersion ?? HttpVersion.Version11); + httpRequestMessage.set_RequestUri(requestUri); + httpRequestMessage.set_Method(httpMethod); + return httpRequestMessage; + } + + public static FormUrlEncodedContent Encode(this List> keyValuePairs) + { + return new FormUrlEncodedContent(keyValuePairs); + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs new file mode 100644 index 0000000..58dba77 --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs @@ -0,0 +1,20 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Gestor.Common.Helpers +{ + [AttributeUsage(AttributeTargets.All)] + public class OrderAttribute : Attribute + { + public int OrderProperty + { + get; + private set; + } + + public OrderAttribute(int orderProperty) + { + this.OrderProperty = orderProperty; + } + } +} \ No newline at end of file diff --git a/Codemerx/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs b/Codemerx/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs new file mode 100644 index 0000000..6332e15 --- /dev/null +++ b/Codemerx/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs @@ -0,0 +1,124 @@ +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; + + public static DependencyProperty TimeDurationProperty; + + public static DependencyProperty PointsToScrollProperty; + + public static DependencyProperty IsEnabledProperty; + + private static double _currentToValue; + + private static Storyboard _storyboard; + + static ScrollAnimationBehavior() + { + ScrollAnimationBehavior.VerticalOffsetProperty = DependencyProperty.RegisterAttached("VerticalOffset", typeof(double), typeof(ScrollAnimationBehavior), new UIPropertyMetadata((object)0, new PropertyChangedCallback(ScrollAnimationBehavior.OnVerticalOffsetChanged))); + ScrollAnimationBehavior.TimeDurationProperty = DependencyProperty.RegisterAttached("TimeDuration", typeof(TimeSpan), typeof(ScrollAnimationBehavior), new PropertyMetadata((object)(new TimeSpan(0, 0, 0, 0, 0)))); + ScrollAnimationBehavior.PointsToScrollProperty = DependencyProperty.RegisterAttached("PointsToScroll", typeof(double), typeof(ScrollAnimationBehavior), new PropertyMetadata((object)0)); + ScrollAnimationBehavior.IsEnabledProperty = DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(ScrollAnimationBehavior), new UIPropertyMetadata(false, new PropertyChangedCallback(ScrollAnimationBehavior.OnIsEnabledChanged))); + } + + private static void AnimateScroll(ScrollViewer scrollViewer) + { + DoubleAnimationUsingKeyFrames doubleAnimationUsingKeyFrame = new DoubleAnimationUsingKeyFrames() + { + Duration = new Duration(ScrollAnimationBehavior.GetTimeDuration(scrollViewer)) + }; + doubleAnimationUsingKeyFrame.KeyFrames.Add(new EasingDoubleKeyFrame(scrollViewer.VerticalOffset, KeyTime.FromPercent(0))); + doubleAnimationUsingKeyFrame.KeyFrames.Add(new EasingDoubleKeyFrame(ScrollAnimationBehavior._currentToValue, KeyTime.FromPercent(1), new SineEase() + { + EasingMode = EasingMode.EaseOut + })); + ScrollAnimationBehavior._storyboard = new Storyboard(); + ScrollAnimationBehavior._storyboard.Children.Add(doubleAnimationUsingKeyFrame); + Storyboard.SetTarget(doubleAnimationUsingKeyFrame, scrollViewer); + Storyboard.SetTargetProperty(doubleAnimationUsingKeyFrame, new PropertyPath(ScrollAnimationBehavior.VerticalOffsetProperty)); + ScrollAnimationBehavior._storyboard.Begin(); + } + + public static TimeSpan GetTimeDuration(FrameworkElement target) + { + return (TimeSpan)target.GetValue(ScrollAnimationBehavior.TimeDurationProperty); + } + + private static void OnIsEnabledChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + ScrollViewer scrollViewer = sender as ScrollViewer; + if (scrollViewer != null) + { + scrollViewer.Loaded += new RoutedEventHandler(ScrollAnimationBehavior.ScrollerLoaded); + } + } + + private static void OnVerticalOffsetChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) + { + ScrollViewer scrollViewer = target as ScrollViewer; + if (scrollViewer != null) + { + scrollViewer.ScrollToVerticalOffset((double)e.NewValue); + } + } + + private static void ScrollerLoaded(object sender, RoutedEventArgs e) + { + ScrollAnimationBehavior.SetEventHandlersForScrollViewer(sender as ScrollViewer); + } + + private static void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs e) + { + double num; + double num1 = ScrollAnimationBehavior._currentToValue; + double delta = (double)e.Delta; + ScrollViewer scrollViewer = (ScrollViewer)sender; + double num2 = delta * 2 / 3; + if (ScrollAnimationBehavior._storyboard == null || ScrollAnimationBehavior._storyboard.GetCurrentState() == ClockState.Filling) + { + ScrollAnimationBehavior._currentToValue = scrollViewer.VerticalOffset; + } + if (num2 > ScrollAnimationBehavior._currentToValue) + { + num = 0; + } + else + { + num = (ScrollAnimationBehavior._currentToValue - num2 > scrollViewer.ScrollableHeight ? scrollViewer.ScrollableHeight : ScrollAnimationBehavior._currentToValue - num2); + } + ScrollAnimationBehavior._currentToValue = num; + if (ScrollAnimationBehavior._currentToValue != scrollViewer.VerticalOffset && ScrollAnimationBehavior._currentToValue != num1) + { + ScrollAnimationBehavior.AnimateScroll(scrollViewer); + } + e.Handled = true; + } + + private static void SetEventHandlersForScrollViewer(ScrollViewer scroller) + { + scroller.PreviewMouseWheel += new MouseWheelEventHandler(ScrollAnimationBehavior.ScrollViewerPreviewMouseWheel); + } + + public static void SetIsEnabled(FrameworkElement target, bool value) + { + target.SetValue(ScrollAnimationBehavior.IsEnabledProperty, value); + } + + public static void SetPointsToScroll(FrameworkElement target, double value) + { + target.SetValue(ScrollAnimationBehavior.PointsToScrollProperty, value); + } + + public static void SetTimeDuration(FrameworkElement target, TimeSpan value) + { + target.SetValue(ScrollAnimationBehavior.TimeDurationProperty, value); + } + } +} \ No newline at end of file -- cgit v1.2.3