diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-04-17 23:59:44 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-17 14:59:44 -0700 |
commit | cdd6d4defc844b605890e7ad731e27e373b09bf4 (patch) | |
tree | ddf897b6bf475273a247891898a6c7daf7fb2079 /Xamarin.Forms.Xaml | |
parent | 0b10ab0c130c814b4ab1595c8d13c4c6c9c9d5df (diff) | |
download | xamarin-forms-cdd6d4defc844b605890e7ad731e27e373b09bf4.tar.gz xamarin-forms-cdd6d4defc844b605890e7ad731e27e373b09bf4.tar.bz2 xamarin-forms-cdd6d4defc844b605890e7ad731e27e373b09bf4.zip |
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
Diffstat (limited to 'Xamarin.Forms.Xaml')
-rw-r--r-- | Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs | 4 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml/CreateValuesVisitor.cs | 4 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml/FillResourceDictionariesVisitor.cs | 29 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml/HydratationContext.cs | 6 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml/ViewExtensions.cs | 4 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml/XamlLoader.cs | 4 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml/XamlNode.cs | 16 |
7 files changed, 47 insertions, 20 deletions
diff --git a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs index 8978f4fd..0a0651a7 100644 --- a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs +++ b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs @@ -133,7 +133,7 @@ namespace Xamarin.Forms.Xaml if (typeof (IEnumerable).GetTypeInfo().IsAssignableFrom(Context.Types[parentElement].GetTypeInfo())) { var source = Values[parentNode]; - if (Context.Types[parentElement] != typeof (ResourceDictionary)) + if (!(typeof (ResourceDictionary).IsAssignableFrom(Context.Types[parentElement]))) { var addMethod = Context.Types[parentElement].GetRuntimeMethods().First(mi => mi.Name == "Add" && mi.GetParameters().Length == 1); @@ -291,7 +291,7 @@ namespace Xamarin.Forms.Xaml return null; } - public static void SetPropertyValue(object xamlelement, XmlName propertyName, object value, BindableObject rootElement, + public static void SetPropertyValue(object xamlelement, XmlName propertyName, object value, object rootElement, INode node, HydratationContext context, IXmlLineInfo lineInfo) { var elementType = xamlelement.GetType(); diff --git a/Xamarin.Forms.Xaml/CreateValuesVisitor.cs b/Xamarin.Forms.Xaml/CreateValuesVisitor.cs index d54a36d5..612b32f1 100644 --- a/Xamarin.Forms.Xaml/CreateValuesVisitor.cs +++ b/Xamarin.Forms.Xaml/CreateValuesVisitor.cs @@ -149,7 +149,9 @@ namespace Xamarin.Forms.Xaml var rnode = (XamlLoader.RuntimeRootNode)node; Values[node] = rnode.Root; Context.Types[node] = rnode.Root.GetType(); - NameScope.SetNameScope(rnode.Root as BindableObject, node.Namescope); + var bindableRoot = rnode.Root as BindableObject; + if (bindableRoot != null) + NameScope.SetNameScope(bindableRoot, node.Namescope); } public void Visit(ListNode node, INode parentNode) 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<string> ())).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) diff --git a/Xamarin.Forms.Xaml/HydratationContext.cs b/Xamarin.Forms.Xaml/HydratationContext.cs index 7c1356d9..7273a2cc 100644 --- a/Xamarin.Forms.Xaml/HydratationContext.cs +++ b/Xamarin.Forms.Xaml/HydratationContext.cs @@ -17,8 +17,8 @@ namespace Xamarin.Forms.Xaml public HydratationContext ParentContext { get; set; } - public BindableObject RootElement { get; set; } - public bool DoNotThrowOnExceptions { get; set; } + + public object RootElement { get; set; } } -}
\ No newline at end of file +} diff --git a/Xamarin.Forms.Xaml/ViewExtensions.cs b/Xamarin.Forms.Xaml/ViewExtensions.cs index fb8a612a..38d5becf 100644 --- a/Xamarin.Forms.Xaml/ViewExtensions.cs +++ b/Xamarin.Forms.Xaml/ViewExtensions.cs @@ -31,13 +31,13 @@ namespace Xamarin.Forms.Xaml { public static class Extensions { - public static TView LoadFromXaml<TView>(this TView view, Type callingType) where TView : BindableObject + public static TXaml LoadFromXaml<TXaml>(this TXaml view, Type callingType) { XamlLoader.Load(view, callingType); return view; } - internal static TView LoadFromXaml<TView>(this TView view, string xaml) where TView : BindableObject + internal static TXaml LoadFromXaml<TXaml>(this TXaml view, string xaml) { XamlLoader.Load(view, xaml); return view; diff --git a/Xamarin.Forms.Xaml/XamlLoader.cs b/Xamarin.Forms.Xaml/XamlLoader.cs index 575f2c7d..37bea4e4 100644 --- a/Xamarin.Forms.Xaml/XamlLoader.cs +++ b/Xamarin.Forms.Xaml/XamlLoader.cs @@ -39,7 +39,7 @@ namespace Xamarin.Forms.Xaml { static readonly Dictionary<Type, string> XamlResources = new Dictionary<Type, string>(); - public static void Load(BindableObject view, Type callingType) + public static void Load(object view, Type callingType) { var xaml = GetXamlForType(callingType); if (string.IsNullOrEmpty(xaml)) @@ -47,7 +47,7 @@ namespace Xamarin.Forms.Xaml Load(view, xaml); } - public static void Load(BindableObject view, string xaml) + public static void Load(object view, string xaml) { using (var reader = XmlReader.Create(new StringReader(xaml))) { diff --git a/Xamarin.Forms.Xaml/XamlNode.cs b/Xamarin.Forms.Xaml/XamlNode.cs index aa8e6c82..6d84c67d 100644 --- a/Xamarin.Forms.Xaml/XamlNode.cs +++ b/Xamarin.Forms.Xaml/XamlNode.cs @@ -159,7 +159,7 @@ namespace Xamarin.Forms.Xaml visitor.Visit(this, parentNode); } - static bool IsDataTemplate(INode node, INode parentNode) + internal static bool IsDataTemplate(INode node, INode parentNode) { var parentElement = parentNode as IElementNode; INode createContent; @@ -169,7 +169,7 @@ namespace Xamarin.Forms.Xaml return false; } - static bool IsResourceDictionary(INode node, INode parentNode) + internal static bool IsResourceDictionary(INode node, INode parentNode) { var enode = node as ElementNode; return enode.XmlType.Name == "ResourceDictionary"; @@ -186,10 +186,14 @@ namespace Xamarin.Forms.Xaml { if (!visitor.VisitChildrenFirst) visitor.Visit(this, parentNode); - foreach (var node in Properties.Values.ToList()) - node.Accept(visitor, this); - foreach (var node in CollectionItems) - node.Accept(visitor, this); + if ((!visitor.StopOnDataTemplate || !IsDataTemplate(this, parentNode)) && + (!visitor.StopOnResourceDictionary || !IsResourceDictionary(this, parentNode))) + { + foreach (var node in Properties.Values.ToList()) + node.Accept(visitor, this); + foreach (var node in CollectionItems) + node.Accept(visitor, this); + } if (visitor.VisitChildrenFirst) visitor.Visit(this, parentNode); } |