From 86a48cf7d583539744c7f82611e5b02f4e636fae Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Tue, 11 Jun 2019 19:08:25 +0300 Subject: [PATCH] Fixed #2561 --- src/Avalonia.Build.Tasks/Program.cs | 11 ++++- .../XamlIlAvaloniaPropertyHelper.cs | 2 +- .../Xaml/XamlIlTests.cs | 42 +++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Build.Tasks/Program.cs b/src/Avalonia.Build.Tasks/Program.cs index c2d0950264..d356b15408 100644 --- a/src/Avalonia.Build.Tasks/Program.cs +++ b/src/Avalonia.Build.Tasks/Program.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.IO; +using System.Linq; using Microsoft.Build.Framework; namespace Avalonia.Build.Tasks @@ -11,8 +12,14 @@ namespace Avalonia.Build.Tasks { if (args.Length != 3) { - Console.Error.WriteLine("input references output"); - return 1; + if (args.Length == 1) + args = new[] {"original.dll", "references", "out.dll"} + .Select(x => Path.Combine(args[0], x)).ToArray(); + else + { + Console.Error.WriteLine("input references output"); + return 1; + } } return new CompileAvaloniaXamlTask() diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs index 452bb05132..34a79a4cdc 100644 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/XamlIlAvaloniaPropertyHelper.cs @@ -64,7 +64,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions var tref = XamlIlTypeReferenceResolver.ResolveType(context, xmlOwner, false, lineInfo, true); forgedReference = new XamlIlAstNamePropertyReference(lineInfo, - tref, parsedPropertyName.name, tref); + tref, parsedPropertyName.name, selectorTypeReference); } var clrProperty = diff --git a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs index 5e346e5289..b2cc44291d 100644 --- a/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs +++ b/tests/Avalonia.Markup.Xaml.UnitTests/Xaml/XamlIlTests.cs @@ -207,6 +207,33 @@ namespace Avalonia.Markup.Xaml.UnitTests xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'/>", typeof(XamlIlTests).Assembly); Assert.Equal(Design.GetDataContext(loaded), SomeStaticProperty); } + + [Fact] + public void Attached_Properties_From_Static_Types_Should_Work_In_Style_Setters_Bug_2561() + { + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + + var parsed = (Window)AvaloniaXamlLoader.Parse(@" + + + + + + + +"); + var tb = ((TextBox)parsed.Content); + parsed.Show(); + tb.ApplyTemplate(); + Assert.Equal(100, XamlIlBugTestsStaticClassWithAttachedProperty.GetTestInt(tb)); + } + } } public class XamlIlBugTestsEventHandlerCodeBehind : Window @@ -272,4 +299,19 @@ namespace Avalonia.Markup.Xaml.UnitTests { } + public static class XamlIlBugTestsStaticClassWithAttachedProperty + { + public static readonly AvaloniaProperty TestIntProperty = AvaloniaProperty + .RegisterAttached("TestInt", typeof(XamlIlBugTestsStaticClassWithAttachedProperty)); + + public static void SetTestInt(Control control, int value) + { + control.SetValue(TestIntProperty, value); + } + + public static int GetTestInt(Control control) + { + return (int)control.GetValue(TestIntProperty); + } + } }