From cdd6d4defc844b605890e7ad731e27e373b09bf4 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Sun, 17 Apr 2016 23:59:44 +0200 Subject: Merged ResourceDictionary (#97) * [X] Support Merged RD * [X] Support RD as xaml roots * [XamlC] I have no idea how that used to work before * [C] Remove debugging statements * fix docs --- .../FillResourceDictionariesVisitor.cs | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs') diff --git a/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs b/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs index 5eb47887..c140084a 100644 --- a/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs +++ b/Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs @@ -37,6 +37,27 @@ namespace Xamarin.Forms.Xaml public void Visit(ValueNode node, INode parentNode) { + var parentElement = parentNode as IElementNode; + var value = Values [node]; + var source = Values [parentNode]; + + XmlName propertyName; + if (ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName)) { + if (parentElement.SkipProperties.Contains(propertyName)) + return; + if (parentElement.SkipPrefix(node.NamespaceResolver.LookupPrefix(propertyName.NamespaceURI))) + return; + if (propertyName.NamespaceURI == "http://schemas.openxmlformats.org/markup-compatibility/2006" && + propertyName.LocalName == "Ignorable") { + (parentNode.IgnorablePrefixes ?? (parentNode.IgnorablePrefixes = new List ())).AddRange ( + (value as string).Split (',')); + return; + } + if (propertyName.LocalName != "MergedWith") + return; + ApplyPropertiesVisitor.SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node); + } + } public void Visit(MarkupNode node, INode parentNode) @@ -56,10 +77,10 @@ namespace Xamarin.Forms.Xaml //Set Resources in ResourcesDictionaries if (IsCollectionItem(node, parentNode) && parentNode is IElementNode) { - if (typeof (IEnumerable).GetTypeInfo().IsAssignableFrom(Context.Types[parentElement].GetTypeInfo())) + if (typeof (IEnumerable).IsAssignableFrom(Context.Types[parentElement])) { var source = Values[parentNode]; - if (Context.Types[parentElement] == typeof (ResourceDictionary) && value is Style && + if (typeof (ResourceDictionary).IsAssignableFrom(Context.Types[parentElement]) && value is Style && !node.Properties.ContainsKey(XmlName.xKey)) { node.Accept(new ApplyPropertiesVisitor(Context), parentNode); @@ -75,9 +96,9 @@ namespace Xamarin.Forms.Xaml } ((ResourceDictionary)source).Add(value as Style); } - else if (Context.Types[parentElement] == typeof (ResourceDictionary) && !node.Properties.ContainsKey(XmlName.xKey)) + else if (typeof (ResourceDictionary).IsAssignableFrom(Context.Types[parentElement]) && !node.Properties.ContainsKey(XmlName.xKey)) throw new XamlParseException("resources in ResourceDictionary require a x:Key attribute", node); - else if (Context.Types[parentElement] == typeof (ResourceDictionary) && node.Properties.ContainsKey(XmlName.xKey)) + else if (typeof (ResourceDictionary).IsAssignableFrom(Context.Types[parentElement]) && node.Properties.ContainsKey(XmlName.xKey)) { node.Accept(new ApplyPropertiesVisitor(Context), parentNode); if (markupExtension != null) -- cgit v1.2.3