summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.Design/AttributeTableBuilder.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Core.Design/AttributeTableBuilder.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Core.Design/AttributeTableBuilder.cs')
-rw-r--r--Xamarin.Forms.Core.Design/AttributeTableBuilder.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.Design/AttributeTableBuilder.cs b/Xamarin.Forms.Core.Design/AttributeTableBuilder.cs
new file mode 100644
index 00000000..07571d4c
--- /dev/null
+++ b/Xamarin.Forms.Core.Design/AttributeTableBuilder.cs
@@ -0,0 +1,74 @@
+using System;
+using System.ComponentModel;
+using System.Linq;
+using System.Windows.Markup;
+using Microsoft.Windows.Design;
+
+namespace Xamarin.Forms.Core.Design
+{
+ internal class AttributeTableBuilder : Microsoft.Windows.Design.Metadata.AttributeTableBuilder
+ {
+ public AttributeTableBuilder ()
+ {
+ // Turn off validation of values, which doesn't work for OnPlatform/OnIdiom
+ AddCustomAttributes (typeof (AbsoluteLayout).Assembly,
+ new XmlnsSupportsValidationAttribute ("http://xamarin.com/schemas/2014/forms", false));
+
+ // Style isn't a view, make it visible
+ AddCallback (typeof(Style), builder => builder.AddCustomAttributes(
+ new EditorBrowsableAttribute (EditorBrowsableState.Always),
+ new System.Windows.Markup.ContentPropertyAttribute("Setters"),
+ // Since the class doesn't have a public parameterless ctor, we need to provide a converter
+ new System.ComponentModel.TypeConverterAttribute(typeof(StringConverter))));
+
+ // The Setter.Value can actually come from an <OnPlatform />, so enable it as Content.
+ AddCallback (typeof (Setter), builder => builder.AddCustomAttributes (
+ new EditorBrowsableAttribute (EditorBrowsableState.Always),
+ new System.Windows.Markup.ContentPropertyAttribute("Value")));
+
+ // Special case for FontSize which isn't an enum.
+ var fontElements = typeof(View).Assembly.ExportedTypes.Where(t => typeof(IFontElement).IsAssignableFrom(t));
+ foreach (var fontElement in fontElements) {
+ AddCallback (fontElement, builder => builder.AddCustomAttributes (
+ "FontSize",
+ new System.ComponentModel.TypeConverterAttribute (typeof (EnumConverter<NamedSize>))));
+ }
+
+ // TODO: OnPlatform/OnIdiom
+ // These two should be proper markup extensions, to follow WPF syntax for those.
+ // That would allow us to turn on XAML validation, which otherwise fails.
+ // NOTE: the two also need to provide a non-generic, object-based T so that
+ // the language service can find the type by its name. That class can be internal
+ // though, since its visibility in the markup is controlled by the EditorBrowsableAttribute.
+ // Make OnPlatform/OnIdiom visible for intellisense, and set as markup extension.
+ AddCallback (typeof (OnPlatform<>), builder => builder.AddCustomAttributes (new Attribute[] {
+ new EditorBrowsableAttribute (EditorBrowsableState.Always),
+ //new System.ComponentModel.TypeConverterAttribute(typeof(AnythingConverter)),
+ //new System.Windows.Markup.MarkupExtensionReturnTypeAttribute (),
+ }));
+ AddCallback (typeof (OnIdiom<>), builder => builder.AddCustomAttributes (new Attribute[] {
+ new EditorBrowsableAttribute (EditorBrowsableState.Always),
+ //new System.ComponentModel.TypeConverterAttribute(typeof(AnythingConverter)),
+ //new System.Windows.Markup.MarkupExtensionReturnTypeAttribute (),
+ }));
+ }
+ }
+
+ internal class AnythingConverter : System.ComponentModel.TypeConverter
+ {
+ public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
+ {
+ return true;
+ }
+
+ public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
+ {
+ return true;
+ }
+
+ public override bool IsValid (ITypeDescriptorContext context, object value)
+ {
+ return true;
+ }
+ }
+} \ No newline at end of file