/
KeyboardDesignTypeConverter.cs
55 lines (47 loc) · 1.2 KB
/
KeyboardDesignTypeConverter.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
namespace Xamarin.Forms.Core.Design
{
using System.Linq;
using System.ComponentModel;
using System;
using System.Reflection;
public class KeyboardDesignTypeConverter : TypeConverter
{
public KeyboardDesignTypeConverter()
{
}
protected StandardValuesCollection Values
{
get;
set;
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
// This tells XAML this converter can be used to process strings
// Without this the values won't show up as hints
if (sourceType == typeof(string))
return true;
return base.CanConvertFrom(context, sourceType);
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
if (Values == null)
{
var props = typeof(Keyboard)
.GetProperties(BindingFlags.Static | BindingFlags.Public)
.Where(p => p.CanRead)
.Select(p => p.Name)
.ToArray();
Values = new StandardValuesCollection(props);
}
return Values;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}