diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-22 17:02:53 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-07-22 17:02:53 +0300 |
| commit | e1591a99369da5ec070e6642b330869801f709ec (patch) | |
| tree | de95c5f9b4b034a09ea1bfb9db80c57ba70779d3 /Software/Visual_Studio/Tango.Core/ExtensionMethods | |
| parent | 3fe33a685c3ca7a8730dacffa5357f77d7e76a96 (diff) | |
| download | Tango-e1591a99369da5ec070e6642b330869801f709ec.tar.gz Tango-e1591a99369da5ec070e6642b330869801f709ec.zip | |
Implemented new notification panel.
Optimized usb port scanner.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs index 5a5efd6ad..2e1791b63 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs @@ -10,6 +10,7 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Markup; using System.Windows.Media; +using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using Tango.Core.EventArguments; @@ -492,4 +493,61 @@ public static class FrameworkElementExtensions } #endregion + + #region Animations + + /// <summary> + /// Starts a double animation on the specified property. + /// </summary> + /// <param name="element">The element.</param> + /// <param name="property">The property.</param> + /// <param name="duration">The duration.</param> + /// <param name="acceleration">The acceleration.</param> + /// <param name="deceleration">The deceleration.</param> + /// <param name="onComplete">The on complete.</param> + /// <returns></returns> + public static DoubleAnimation StartDoubleAnimation(this FrameworkElement element, DependencyProperty property, TimeSpan duration, double to, double? from = null, double? acceleration = null, double? deceleration = null, Action onComplete = null) + { + DoubleAnimation ani = new DoubleAnimation(); + ani.Duration = duration; + + if (acceleration.HasValue) + { + ani.AccelerationRatio = acceleration.Value; + } + + if (deceleration.HasValue) + { + ani.DecelerationRatio = deceleration.Value; + } + + if (ani.From.HasValue) + { + ani.From = from.Value; + } + + ani.To = to; + + ani.Completed += (x, y) => onComplete?.Invoke(); + element.BeginAnimation(property, ani); + return ani; + } + + #endregion + + #region Size + + /// <summary> + /// Ensures the element has height other than NaN. If the element height equals NaN, the method will assign ActualHeight to Height. + /// </summary> + /// <param name="element">The element.</param> + public static void EnsureHeight(this FrameworkElement element) + { + if (double.IsNaN(element.Height)) + { + element.Height = element.ActualHeight; + } + } + + #endregion } |
