summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/Extensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/Extensions.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/Extensions.cs46
1 files changed, 46 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/Extensions.cs b/Xamarin.Forms.Platform.WinRT/Extensions.cs
new file mode 100644
index 00000000..3d4431f1
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/Extensions.cs
@@ -0,0 +1,46 @@
+using System;
+using System.Runtime.CompilerServices;
+using Windows.Foundation;
+using Windows.UI;
+using Windows.UI.Xaml;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ internal static class Extensions
+ {
+ public static ConfiguredTaskAwaitable<T> DontSync<T>(this IAsyncOperation<T> self)
+ {
+ return self.AsTask().ConfigureAwait(false);
+ }
+
+ public static ConfiguredTaskAwaitable DontSync(this IAsyncAction self)
+ {
+ return self.AsTask().ConfigureAwait(false);
+ }
+
+ public static Windows.UI.Color GetIdealForegroundForBackgroundColor(this Windows.UI.Color backgroundColor)
+ {
+ var nThreshold = 105;
+ int bgLuminance = Convert.ToInt32(backgroundColor.R * 0.2 + backgroundColor.G * 0.7 + backgroundColor.B * 0.1);
+
+ Windows.UI.Color foregroundColor = 255 - bgLuminance < nThreshold ? Colors.Black : Colors.White;
+ return foregroundColor;
+ }
+
+ public static void SetBinding(this FrameworkElement self, DependencyProperty property, string path)
+ {
+ self.SetBinding(property, new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath(path) });
+ }
+
+ public static void SetBinding(this FrameworkElement self, DependencyProperty property, string path, Windows.UI.Xaml.Data.IValueConverter converter)
+ {
+ self.SetBinding(property, new Windows.UI.Xaml.Data.Binding { Path = new PropertyPath(path), Converter = converter });
+ }
+ }
+} \ No newline at end of file