summaryrefslogtreecommitdiff
path: root/Gestor.Common/Gestor.Common.Helpers
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Gestor.Common/Gestor.Common.Helpers
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Gestor.Common/Gestor.Common.Helpers')
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs14
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs19
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs106
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs59
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs166
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs32
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs38
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/Functions.cs110
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs12
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs25
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs20
-rw-r--r--Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs124
12 files changed, 0 insertions, 725 deletions
diff --git a/Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs b/Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs
deleted file mode 100644
index 03ccc65..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/DataBaseParameters.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-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/Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs b/Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs
deleted file mode 100644
index b79d623..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/DefaultAttribute.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-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/Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs b/Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs
deleted file mode 100644
index b2102d2..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/EncryptionHelper.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-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/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs b/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs
deleted file mode 100644
index 7ce699e..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/EnumBindingSourceExtension.cs
+++ /dev/null
@@ -1,59 +0,0 @@
-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/Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs b/Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs
deleted file mode 100644
index 33529b8..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/EnumHelper.cs
+++ /dev/null
@@ -1,166 +0,0 @@
-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<T, T2>(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<T>(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<T>(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<T>(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<T>(this T enumValue)
- {
- OldValueAttribute attribute = enumValue.GetAttribute<T, OldValueAttribute>();
- if (attribute != null)
- {
- return attribute.OldValue;
- }
- return null;
- }
-
- public static string GetOldValue2<T>(this T enumValue)
- {
- OldValue2Attribute attribute = enumValue.GetAttribute<T, OldValue2Attribute>();
- if (attribute != null)
- {
- return attribute.OldValue2;
- }
- return null;
- }
-
- public static int? GetOrder<T>(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<T>(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<T>(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<T>(this T enumValue)
- {
- return Convert.ToInt32(enumValue).ToString();
- }
- }
-} \ No newline at end of file
diff --git a/Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs b/Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs
deleted file mode 100644
index 4cabf7c..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/FindVisualChild.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System;
-using System.Windows;
-using System.Windows.Media;
-
-namespace Gestor.Common.Helpers
-{
- public class FindVisualChild
- {
- public FindVisualChild()
- {
- }
-
- public static childItem Find<childItem>(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<childItem>(child);
- if (_childItem != null)
- {
- return _childItem;
- }
- }
- return default(childItem);
- }
- }
-} \ No newline at end of file
diff --git a/Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs b/Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs
deleted file mode 100644
index 9b7f11d..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/FindVisualChildren.cs
+++ /dev/null
@@ -1,38 +0,0 @@
-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<T> Find<T>(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<T>(dependencyObject))
- {
- yield return t;
- }
- dependencyObject = null;
- }
- }
- }
- }
-} \ No newline at end of file
diff --git a/Gestor.Common/Gestor.Common.Helpers/Functions.cs b/Gestor.Common/Gestor.Common.Helpers/Functions.cs
deleted file mode 100644
index 25ffadf..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/Functions.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-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<IPAddress>)Dns.GetHostEntry("time.google.com").AddressList).First<IPAddress>((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/Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs b/Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs
deleted file mode 100644
index 236be6f..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/HiddenAttribute.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using System;
-
-namespace Gestor.Common.Helpers
-{
- [AttributeUsage(AttributeTargets.All)]
- public class HiddenAttribute : Attribute
- {
- public HiddenAttribute()
- {
- }
- }
-} \ No newline at end of file
diff --git a/Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs b/Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs
deleted file mode 100644
index 26b53e3..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/HttpHelper.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-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<KeyValuePair<string, string>> keyValuePairs)
- {
- return new FormUrlEncodedContent(keyValuePairs);
- }
- }
-} \ No newline at end of file
diff --git a/Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs b/Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs
deleted file mode 100644
index 58dba77..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/OrderAttribute.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-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/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs b/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs
deleted file mode 100644
index 6332e15..0000000
--- a/Gestor.Common/Gestor.Common.Helpers/ScrollAnimationBehavior.cs
+++ /dev/null
@@ -1,124 +0,0 @@
-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