summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs6
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml13
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs66
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs2
-rw-r--r--Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs16
-rw-r--r--Xamarin.Forms.Xaml/XamlNode.cs42
7 files changed, 144 insertions, 7 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs b/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs
index 63493030..7361235c 100644
--- a/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/MarkupExpressionParserTests.cs
@@ -68,7 +68,13 @@ namespace Xamarin.Forms.Xaml.UnitTests
throw new NotImplementedException ();
}
+
public List<string> IgnorablePrefixes { get; set; }
+
+ public INode Clone()
+ {
+ throw new NotImplementedException();
+ }
}
[SetUp]
diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml b/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml
new file mode 100644
index 00000000..738fac60
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ListView xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.TypeExtension">
+ <ListView.ItemTemplate>
+ <DataTemplate>
+ <ViewCell>
+ <Button Command="{local:Navigate Operation=Forward, Type={x:Type Grid}}" />
+ </ViewCell>
+ </DataTemplate>
+ </ListView.ItemTemplate>
+</ListView> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs
new file mode 100644
index 00000000..6f9ef80a
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/TypeExtension.xaml.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Windows.Input;
+using Xamarin.Forms;
+using NUnit.Framework;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public enum NavigationOperation
+ {
+ Forward,
+ Back,
+ Replace,
+ }
+
+ [ContentProperty(nameof(Operation))]
+ public class NavigateExtension : IMarkupExtension<ICommand>
+ {
+ public NavigationOperation Operation { get; set; }
+
+ public Type Type { get; set; }
+
+ public ICommand ProvideValue(IServiceProvider serviceProvider)
+ {
+ return new Command(() => { });
+ }
+
+ object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
+ {
+ return ProvideValue(serviceProvider);
+ }
+ }
+
+ public partial class TypeExtension : ListView
+ {
+ public TypeExtension()
+ {
+ InitializeComponent();
+ }
+
+ public TypeExtension(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ public class Tests
+ {
+ [TestCase(false)]
+ [TestCase(true)]
+ public void NestedMarkupExtensionInsideDataTemplate(bool useCompiledXaml)
+ {
+ var listView = new TypeExtension(useCompiledXaml);
+ listView.ItemsSource = new string [2];
+
+ var cell = (ViewCell)listView.TemplatedItems [0];
+ var button = (Button)cell.View;
+ Assert.IsNotNull(button.Command);
+
+ cell = (ViewCell)listView.TemplatedItems [1];
+ button = (Button)cell.View;
+ Assert.IsNotNull(button.Command);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index 577b68bb..4f67feb1 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -353,6 +353,9 @@
<Compile Include="SetValue.xaml.cs">
<DependentUpon>SetValue.xaml</DependentUpon>
</Compile>
+ <Compile Include="TypeExtension.xaml.cs">
+ <DependentUpon>TypeExtension.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -629,6 +632,9 @@
<EmbeddedResource Include="SetValue.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="TypeExtension.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
diff --git a/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs
index 23c72a00..e5486e74 100644
--- a/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/XamlLoaderCreateTests.cs
@@ -1,5 +1,7 @@
using System;
+using System.Windows.Input;
using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
diff --git a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
index 108d707e..327a4122 100644
--- a/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
+++ b/Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
@@ -433,14 +433,16 @@ namespace Xamarin.Forms.Xaml
((IDataTemplate)dt).LoadTemplate = () =>
{
#pragma warning restore 0612
+ var cnode = node.Clone();
var context = new HydratationContext { ParentContext = Context, RootElement = Context.RootElement };
- node.Accept(new ExpandMarkupsVisitor(context), null);
- node.Accept(new NamescopingVisitor(context), null);
- node.Accept(new CreateValuesVisitor(context), null);
- node.Accept(new RegisterXNamesVisitor(context), null);
- node.Accept(new FillResourceDictionariesVisitor(context), null);
- node.Accept(new ApplyPropertiesVisitor(context, true), null);
- return context.Values[node];
+ cnode.Accept(new XamlNodeVisitor((n, parent) => n.Parent = parent), node.Parent); //set parents for {StaticResource}
+ cnode.Accept(new ExpandMarkupsVisitor(context), null);
+ cnode.Accept(new NamescopingVisitor(context), null);
+ cnode.Accept(new CreateValuesVisitor(context), null);
+ cnode.Accept(new RegisterXNamesVisitor(context), null);
+ cnode.Accept(new FillResourceDictionariesVisitor(context), null);
+ cnode.Accept(new ApplyPropertiesVisitor(context, true), null);
+ return context.Values[cnode];
};
}
}
diff --git a/Xamarin.Forms.Xaml/XamlNode.cs b/Xamarin.Forms.Xaml/XamlNode.cs
index 6d84c67d..f794428b 100644
--- a/Xamarin.Forms.Xaml/XamlNode.cs
+++ b/Xamarin.Forms.Xaml/XamlNode.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -15,6 +16,7 @@ namespace Xamarin.Forms.Xaml
INode Parent { get; set; }
void Accept(IXamlNodeVisitor visitor, INode parentNode);
+ INode Clone();
}
internal interface IValueNode : INode
@@ -81,6 +83,8 @@ namespace Xamarin.Forms.Xaml
public int LineNumber { get; set; }
public int LinePosition { get; set; }
+
+ public abstract INode Clone();
}
[DebuggerDisplay("{Value}")]
@@ -98,6 +102,13 @@ namespace Xamarin.Forms.Xaml
{
visitor.Visit(this, parentNode);
}
+
+ public override INode Clone()
+ {
+ return new ValueNode(Value, NamespaceResolver, LineNumber, LinePosition) {
+ IgnorablePrefixes = IgnorablePrefixes
+ };
+ }
}
[DebuggerDisplay("{MarkupString}")]
@@ -116,6 +127,13 @@ namespace Xamarin.Forms.Xaml
{
visitor.Visit(this, parentNode);
}
+
+ public override INode Clone()
+ {
+ return new MarkupNode(MarkupString, NamespaceResolver, LineNumber, LinePosition) {
+ IgnorablePrefixes = IgnorablePrefixes
+ };
+ }
}
internal class ElementNode : BaseNode, IValueNode, IElementNode
@@ -174,6 +192,20 @@ namespace Xamarin.Forms.Xaml
var enode = node as ElementNode;
return enode.XmlType.Name == "ResourceDictionary";
}
+
+ public override INode Clone()
+ {
+ var clone = new ElementNode(XmlType, NamespaceURI, NamespaceResolver, LineNumber, LinePosition) {
+ IgnorablePrefixes = IgnorablePrefixes
+ };
+ foreach (var kvp in Properties)
+ clone.Properties.Add(kvp.Key, kvp.Value.Clone());
+ foreach (var p in SkipProperties)
+ clone.SkipProperties.Add(p);
+ foreach (var p in CollectionItems)
+ clone.CollectionItems.Add(p.Clone());
+ return clone;
+ }
}
internal abstract class RootNode : ElementNode
@@ -220,6 +252,16 @@ namespace Xamarin.Forms.Xaml
if (visitor.VisitChildrenFirst)
visitor.Visit(this, parentNode);
}
+
+ public override INode Clone()
+ {
+ var items = new List<INode>();
+ foreach (var p in CollectionItems)
+ items.Add(p.Clone());
+ return new ListNode(items, NamespaceResolver, LineNumber, LinePosition) {
+ IgnorablePrefixes = IgnorablePrefixes
+ };
+ }
}
internal static class INodeExtensions