[XamlC] complete the Setter/Trigger fix (#737)
authorStephane Delcroix <stephane@delcroix.org>
Mon, 13 Feb 2017 11:19:05 +0000 (12:19 +0100)
committerRui Marinho <me@ruimarinho.net>
Thu, 9 Mar 2017 18:52:40 +0000 (18:52 +0000)
Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml [new file with mode: 0644]
Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml.cs [new file with mode: 0644]
Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj

index e417f11..e8bca7c 100644 (file)
@@ -14,7 +14,9 @@ namespace Xamarin.Forms.Core.XamlC
                public IEnumerable<Instruction> 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)
index e00a1c1..6b4f0b6 100644 (file)
@@ -14,7 +14,9 @@ namespace Xamarin.Forms.Core.XamlC
                public IEnumerable<Instruction> 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 (file)
index 0000000..62771ef
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+       x:Class="Xamarin.Forms.Xaml.UnitTests.Unreported009">
+       <ContentPage.Resources>
+               <ResourceDictionary>
+                       <Style x:Key="Default" TargetType="ContentView">
+                               <Setter Property="Content">
+                                       <Setter.Value>
+                                               <Label Text="Bananas!" />
+                                       </Setter.Value>
+                               </Setter>
+                       </Style>>
+               </ResourceDictionary>
+       </ContentPage.Resources>
+</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported009.xaml.cs
new file mode 100644 (file)
index 0000000..e825b5b
--- /dev/null
@@ -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);
+                       }
+               }
+       }
+}
index 2baacb0..ab71d75 100644 (file)
     <Compile Include="Issues\Bz51567.xaml.cs">
       <DependentUpon>Bz51567.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Issues\Bz42531.xaml.cs">
+      <DependentUpon>Bz42531.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Issues\Bz45299.xaml.cs">
+      <DependentUpon>Bz45299.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Issues\Bz43733.xaml.cs">
+      <DependentUpon>Bz43733.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Issues\Bz44213.xaml.cs">
+      <DependentUpon>Bz44213.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="DefaultCtorRouting.xaml.cs">
+      <DependentUpon>DefaultCtorRouting.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="DefaultCtorRouting2.xaml.cs">
+      <DependentUpon>DefaultCtorRouting2.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Issues\Bz43694.xaml.cs">
+      <DependentUpon>Bz43694.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Issues\Bz45891.xaml.cs">
+      <DependentUpon>Bz45891.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Issues\Bz44216.xaml.cs">
+      <DependentUpon>Bz44216.xaml</DependentUpon>
+      <DependentUpon>AcceptEmptyServiceProvider.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="AcceptEmptyServiceProvider.xaml.cs">
+      <DependentUpon>AcceptEmptyServiceProvider.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="Issues\Unreported009.xaml.cs">
+      <DependentUpon>Unreported009.xaml</DependentUpon>
+    </Compile>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
     <EmbeddedResource Include="Issues\Bz51567.xaml">
       <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
     </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Bz42531.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Bz45299.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Bz43733.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Bz44213.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="DefaultCtorRouting.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="DefaultCtorRouting2.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Bz43694.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Bz45891.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Bz44216.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="AcceptEmptyServiceProvider.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Issues\Unreported009.xaml">
+      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+    </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
     <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />