From 1068d53e021b3a541414ddd47a3b35782d757caa Mon Sep 17 00:00:00 2001 From: Stephane Delcroix Date: Mon, 13 Feb 2017 12:19:05 +0100 Subject: [PATCH] [XamlC] complete the Setter/Trigger fix (#737) --- .../CompiledValueProviders/SetterValueProvider.cs | 4 +- .../CompiledValueProviders/TriggerValueProvider.cs | 4 +- .../Issues/Unreported009.xaml | 16 ++++++ .../Issues/Unreported009.xaml.cs | 45 +++++++++++++++ .../Xamarin.Forms.Xaml.UnitTests.csproj | 67 ++++++++++++++++++++++ 5 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml create mode 100644 Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml.cs diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs index e417f11..e8bca7c 100644 --- a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs +++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs @@ -14,7 +14,9 @@ namespace Xamarin.Forms.Core.XamlC public IEnumerable ProvideValue(VariableDefinitionReference vardefref, ModuleDefinition module, BaseNode node, ILContext context) { INode valueNode = null; - if (!((IElementNode)node).Properties.TryGetValue(new XmlName("", "Value"), out valueNode) && ((IElementNode)node).CollectionItems.Count == 1) + if (!((IElementNode)node).Properties.TryGetValue(new XmlName("", "Value"), out valueNode) && + !((IElementNode)node).Properties.TryGetValue(new XmlName("http://xamarin.com/schemas/2014/forms", "Value"), out valueNode) && + ((IElementNode)node).CollectionItems.Count == 1) valueNode = ((IElementNode)node).CollectionItems[0]; if (valueNode == null) diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs index e00a1c1..6b4f0b6 100644 --- a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs +++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs @@ -14,7 +14,9 @@ namespace Xamarin.Forms.Core.XamlC public IEnumerable ProvideValue(VariableDefinitionReference vardefref, ModuleDefinition module, BaseNode node, ILContext context) { INode valueNode = null; - if (!((IElementNode)node).Properties.TryGetValue(new XmlName("", "Value"), out valueNode) && ((IElementNode)node).CollectionItems.Count == 1) + if (!((IElementNode)node).Properties.TryGetValue(new XmlName("", "Value"), out valueNode) && + !((IElementNode)node).Properties.TryGetValue(new XmlName("http://xamarin.com/schemas/2014/forms", "Value"), out valueNode) && + ((IElementNode)node).CollectionItems.Count == 1) valueNode = ((IElementNode)node).CollectionItems[0]; if (valueNode == null) diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml new file mode 100644 index 0000000..62771ef --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml @@ -0,0 +1,16 @@ + + + + + > + + + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml.cs new file mode 100644 index 0000000..e825b5b --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class Unreported009 : ContentPage + { + public Unreported009() + { + InitializeComponent(); + } + + public Unreported009(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup() + { + Device.PlatformServices = new MockPlatformServices(); + } + + [TearDown] + public void TearDown() + { + Device.PlatformServices = null; + } + + [TestCase(true), TestCase(false)] + public void AllowSetterValueAsElementProperties(bool useCompiledXaml) + { + var p = new Unreported009(useCompiledXaml); + var s = p.Resources["Default"] as Style; + Assert.AreEqual("Bananas!", (s.Setters[0].Value as Label).Text); + } + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj index 2baacb0..ab71d75 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -409,6 +409,40 @@ Bz51567.xaml + + Bz42531.xaml + + + Bz45299.xaml + + + Bz43733.xaml + + + Bz44213.xaml + + + DefaultCtorRouting.xaml + + + DefaultCtorRouting2.xaml + + + Bz43694.xaml + + + Bz45891.xaml + + + Bz44216.xaml + AcceptEmptyServiceProvider.xaml + + + AcceptEmptyServiceProvider.xaml + + + Unreported009.xaml + @@ -739,6 +773,39 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + + + MSBuild:UpdateDesignTimeXaml + -- 2.7.4