-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
VisualDesignTypeConverter.cs
64 lines (52 loc) · 1.49 KB
/
VisualDesignTypeConverter.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
namespace Xamarin.Forms.Core.Design
{
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System;
public class VisualDesignTypeConverter : TypeConverter
{
public VisualDesignTypeConverter()
{
}
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 derivedNames = new List<string>();
var baseType = typeof(IVisual);
var typeElements = typeof(View).Assembly.ExportedTypes.Where(t => baseType.IsAssignableFrom(t) && t.Name != baseType.Name);
foreach (var typeElement in typeElements)
{
string name = typeElement.Name;
if (name.EndsWith("Visual", StringComparison.OrdinalIgnoreCase))
name = name.Substring(0, name.Length - 6);
derivedNames.Add(name);
}
Values = new StandardValuesCollection(derivedNames);
}
return Values;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
}