From a1126ab66bc9bd41cfa32dbefbe5758bcf5b4b32 Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Mon, 15 Aug 2016 22:18:26 +0200 Subject: [Xaml] Simplify listnodes with single elements (#304) --- Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs | 18 +++++++++++++----- Xamarin.Forms.Xaml/XmlName.cs | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'Xamarin.Forms.Xaml') diff --git a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs index 1e332323..108d707e 100644 --- a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs +++ b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs @@ -102,21 +102,29 @@ namespace Xamarin.Forms.Xaml value = valueProvider.ProvideValue(serviceProvider); } - XmlName propertyName; - if (TryGetPropertyName(node, parentNode, out propertyName)) - { + XmlName propertyName = XmlName.Empty; + + //Simplify ListNodes with single elements + var pList = parentNode as ListNode; + if (pList != null && pList.CollectionItems.Count == 1) { + propertyName = pList.XmlName; + parentNode = parentNode.Parent; + parentElement = parentNode as IElementNode; + } + + if (propertyName != XmlName.Empty || TryGetPropertyName(node, parentNode, out propertyName)) { if (Skips.Contains(propertyName)) return; if (parentElement.SkipProperties.Contains(propertyName)) return; - var source = Values[parentNode]; + var source = Values [parentNode]; if (propertyName == XmlName._CreateContent && source is ElementTemplate) SetTemplate(source as ElementTemplate, node); else SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node); - } + } else if (IsCollectionItem(node, parentNode) && parentNode is IElementNode) { // Collection element, implicit content, or implicit collection element. diff --git a/Xamarin.Forms.Xaml/XmlName.cs b/Xamarin.Forms.Xaml/XmlName.cs index e22a162d..09cf3bca 100644 --- a/Xamarin.Forms.Xaml/XmlName.cs +++ b/Xamarin.Forms.Xaml/XmlName.cs @@ -11,6 +11,7 @@ namespace Xamarin.Forms.Xaml public static readonly XmlName xTypeArguments = new XmlName("x", "TypeArguments"); public static readonly XmlName xArguments = new XmlName("x", "Arguments"); public static readonly XmlName xFactoryMethod = new XmlName("x", "xFactoryMethod"); + public static readonly XmlName Empty = new XmlName(); public string NamespaceURI { get; } -- cgit v1.2.3