-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Extensions.cs
103 lines (91 loc) · 2.89 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Xamarin.Forms.Internals;
using WImageSource = Windows.UI.Xaml.Media.ImageSource;
using UwpScrollBarVisibility = Windows.UI.Xaml.Controls.ScrollBarVisibility;
using Windows.UI.Xaml.Media.Imaging;
using Microsoft.Graphics.Canvas.UI.Xaml;
namespace Xamarin.Forms.Platform.UWP
{
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 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 });
}
internal static InputScopeNameValue GetKeyboardButtonType(this ReturnType returnType)
{
switch (returnType)
{
case ReturnType.Default:
case ReturnType.Done:
case ReturnType.Go:
case ReturnType.Next:
case ReturnType.Send:
return InputScopeNameValue.Default;
case ReturnType.Search:
return InputScopeNameValue.Search;
default:
throw new System.NotImplementedException($"ReturnType {returnType} not supported");
}
}
internal static InputScope ToInputScope(this ReturnType returnType)
{
var scopeName = new InputScopeName()
{
NameValue = GetKeyboardButtonType(returnType)
};
var inputScope = new InputScope
{
Names = { scopeName }
};
return inputScope;
}
internal static UwpScrollBarVisibility ToUwpScrollBarVisibility(this ScrollBarVisibility visibility)
{
switch (visibility)
{
case ScrollBarVisibility.Always:
return UwpScrollBarVisibility.Visible;
case ScrollBarVisibility.Default:
return UwpScrollBarVisibility.Auto;
case ScrollBarVisibility.Never:
return UwpScrollBarVisibility.Hidden;
default:
return UwpScrollBarVisibility.Auto;
}
}
public static T Clamp<T>(this T value, T min, T max) where T : IComparable<T>
{
if (value.CompareTo(min) < 0)
return min;
if (value.CompareTo(max) > 0)
return max;
return value;
}
internal static int ToEm(this double pt)
{
return Convert.ToInt32( pt * 0.0624f * 1000); //Coefficient for converting Pt to Em. The value is uniform spacing between characters, in units of 1/1000 of an em.
}
}
}