Browse Source
Merge pull request #8467 from AvaloniaUI/bindings-to-types-should-work
Fix bindings to Types.
pull/8454/head
Nikita Tsukanov
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
12 additions and
1 deletions
-
src/Avalonia.Base/Data/Core/Plugins/InpcPropertyAccessorPlugin.cs
-
tests/Avalonia.Markup.UnitTests/Data/BindingTests.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(); |
|
|
|
|
|
|
|
@ -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<double> DoubleValueProperty = |
|
|
|
|