From 8e57d0b7c6b52e6598570795e206a4a27e7e13b9 Mon Sep 17 00:00:00 2001 From: Takoooooo Date: Fri, 8 Jul 2022 11:52:55 +0300 Subject: [PATCH] Fix bindings to Types. --- .../Data/Core/Plugins/InpcPropertyAccessorPlugin.cs | 2 +- tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs index b93bf87fdf..91d69b5d3d 100644 --- a/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs +++ b/src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs @@ -55,7 +55,7 @@ namespace Avalonia.Data.Core.Plugins private PropertyInfo? GetFirstPropertyWithName(object instance, string propertyName) { - if (instance is IReflectableType reflectableType) + if (instance is IReflectableType reflectableType && instance is not Type) return reflectableType.GetTypeInfo().GetProperty(propertyName, PropertyBindingFlags); var type = instance.GetType(); diff --git a/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs b/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs index 11a22f0dec..f4a4a2934f 100644 --- a/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs +++ b/tests/Avalonia.Markup.UnitTests/Data/BindingTests.cs @@ -637,6 +637,17 @@ namespace Avalonia.Markup.UnitTests.Data Assert.Equal("baz", source["Foo"]); } + [Fact] + public void Binding_To_Types_Should_Work() + { + var type = typeof(string); + var textBlock = new TextBlock() { DataContext = type }; + using (textBlock.Bind(TextBlock.TextProperty, new Binding("Name"))) + { + Assert.Equal("String", textBlock.Text); + }; + } + private class StyledPropertyClass : AvaloniaObject { public static readonly StyledProperty DoubleValueProperty =