diff MetroWpf/MetroWpf.Xaml/Converters/RotationAngleToSimplePositiveAngleConverter.cs @ 15:060f02cd4591

Initial commit, pre airport work
author stevenh7776 stevenhollidge@hotmail.com
date Mon, 12 Mar 2012 23:05:21 +0800
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/MetroWpf.Xaml/Converters/RotationAngleToSimplePositiveAngleConverter.cs	Mon Mar 12 23:05:21 2012 +0800
@@ -0,0 +1,63 @@
+//-----------------------------------------------------------------------
+// <copyright file="RotationAngleToSimplePositiveAngleConverter.cs" company="Microsoft">
+//     Copyright (c) Microsoft Corporation.  All rights reserved.
+// </copyright>
+// <summary>
+//     IValueConverter to convert an angle, in degrees, to a 'simple' angle.
+// </summary>
+//-----------------------------------------------------------------------
+
+namespace MetroWpf.Xaml.Converters
+{
+    using System;
+    using System.Windows.Data;
+
+    /// <summary>
+    /// IValueConverter to convert an angle, in degrees, to a 'simple' angle, that is, an angle which lies between 0 and 360 degrees.
+    /// </summary>
+    public class RotationAngleToSimplePositiveAngleConverter : IValueConverter
+    {
+        /// <summary>
+        /// Converts an angle, in degrees, to a 'simple' angle, that is, an angle which lies between 0 and 360 degrees.
+        /// </summary>
+        /// <param name="value">The original angle, in degrees.</param>
+        /// <param name="targetType">The target type of the conversion.</param>
+        /// <param name="parameter">The converter parameter.</param>
+        /// <param name="culture">The application culture.</param>
+        /// <returns>An angle between 0 and 360 degrees.</returns>
+        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+        {
+            object convertedValue = null;
+            try
+            {
+                double angle = System.Convert.ToDouble(value, culture);
+                angle = angle % 360;
+                if (angle < 0)
+                {
+                    angle += 360.0;
+                }
+
+                convertedValue = angle;
+            }
+            catch (InvalidCastException)
+            {
+                //ClientManager.ServiceProvider.Logger.Warning(e.Message);
+            }
+
+            return convertedValue;
+        }
+
+        /// <summary>
+        /// Converts back to the original angle.  Not implemented.
+        /// </summary>
+        /// <param name="value">The simple angle, in degrees.</param>
+        /// <param name="targetType">The target type of the conversion.</param>
+        /// <param name="parameter">The converter parameter.</param>
+        /// <param name="culture">The application culture.</param>
+        /// <returns>An angle in degrees.</returns>
+        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}