diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs index 8b2a25fb3..6f07b3754 100644 --- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs +++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs @@ -903,6 +903,10 @@ namespace Xamarin.Forms.Build.Tasks if (implicitOperator != null) return true; + //as we're in the SetValue Scenario, we can accept value types, they'll be boxed + if (varValue.VariableType.IsValueType && bpTypeRef.FullName == "System.Object") + return true; + return varValue.VariableType.InheritsFromOrImplements(bpTypeRef); } diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53203.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53203.xaml new file mode 100644 index 000000000..540f476d6 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53203.xaml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53203.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53203.xaml.cs new file mode 100644 index 000000000..829dd5e9c --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Bz53203.xaml.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; + +using NUnit.Framework; + +using Xamarin.Forms.Core.UnitTests; +using Xamarin.Forms; + + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public enum Bz53203Values + { + Unknown, + Good, + Better, + Best + } + + public partial class Bz53203 : ContentPage + { + public static int IntValue = 42; + public static object ObjValue = new object(); + + public static readonly BindableProperty ParameterProperty = BindableProperty.CreateAttached("Parameter", + typeof(object), typeof(Bz53203), null); + + public static object GetParameter(BindableObject obj) => + obj.GetValue(ParameterProperty); + + public static void SetParameter(BindableObject obj, object value) => + obj.SetValue(ParameterProperty, value); + + public Bz53203() + { + InitializeComponent(); + } + + public Bz53203(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)] + public void MarkupOnAttachedBPDoesNotThrowAtCompileTime(bool useCompiledXaml) + { + MockCompiler.Compile(typeof(Bz53203)); + } + + [TestCase(true)] + [TestCase(false)] + public void MarkupOnAttachedBP(bool useCompiledXaml) + { + var page = new Bz53203(useCompiledXaml); + var label = page.label0; + Assert.That(Grid.GetRow(label), Is.EqualTo(42)); + Assert.That(GetParameter(label), Is.EqualTo(Bz53203Values.Better)); + } + + } + } +} \ 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 e2162091d..b9c303502 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -458,6 +458,9 @@ Bz53381App.xaml + + Bz53203.xaml + @@ -836,6 +839,9 @@ MSBuild:UpdateDesignTimeXaml + + MSBuild:UpdateDesignTimeXaml +