From 425aedd4cf2f39680352ba2759f5ae08abe2adb4 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 22 Nov 2023 17:44:42 +0200 Subject: [PATCH] fix(xbind): Fix x:Bind not working properly for private properties --- .../xBindTests/Controls/Functions_Control.xaml | 3 +++ .../xBindTests/Controls/Functions_Control.xaml.cs | 2 ++ .../xBindTests/Given_xBind_Functions.cs | 2 ++ src/Uno.UI/DataBinding/BindingPropertyHelper.cs | 6 +++--- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml b/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml index 4f5167e1d6c3..bacafbca1e26 100644 --- a/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml +++ b/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml @@ -12,6 +12,9 @@ + diff --git a/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml.cs b/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml.cs index 3fdb3ca48bad..b9e0d01efeec 100644 --- a/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml.cs +++ b/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Controls/Functions_Control.xaml.cs @@ -54,6 +54,8 @@ public Functions_Control() this.InitializeComponent(); } + private int PrivateInstanceProperty => 41; + public int InstanceProperty => 42; public static int StaticProperty => 43; diff --git a/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Given_xBind_Functions.cs b/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Given_xBind_Functions.cs index 954f22aada76..e9c621a65e83 100644 --- a/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Given_xBind_Functions.cs +++ b/src/Uno.UI.Tests/Windows_UI_Xaml_Data/xBindTests/Given_xBind_Functions.cs @@ -15,6 +15,7 @@ public void When_Initial_Value() FeatureConfiguration.BindingExpression.HandleSetTargetValueExceptions = false; var SUT = new Functions_Control(); + Assert.AreEqual(string.Empty, SUT._PrivateInstanceProperty.Text); Assert.AreEqual(string.Empty, SUT._InstanceProperty.Text); Assert.AreEqual(string.Empty, SUT._StaticProperty.Text); Assert.AreEqual(string.Empty, SUT._StaticPrivateProperty.Text); @@ -44,6 +45,7 @@ public void When_Initial_Value() SUT.ForceLoaded(); + Assert.AreEqual("41", SUT._PrivateInstanceProperty.Text); Assert.AreEqual("42", SUT._InstanceProperty.Text); Assert.AreEqual("43", SUT._StaticProperty.Text); Assert.AreEqual("44", SUT._StaticPrivateProperty.Text); diff --git a/src/Uno.UI/DataBinding/BindingPropertyHelper.cs b/src/Uno.UI/DataBinding/BindingPropertyHelper.cs index 8c1e6e816e0a..ac620faf3982 100644 --- a/src/Uno.UI/DataBinding/BindingPropertyHelper.cs +++ b/src/Uno.UI/DataBinding/BindingPropertyHelper.cs @@ -313,8 +313,8 @@ private static bool InternalIsEvent(Type type, string property) indexerParameterType = typeof(string); } - var indexerInfo = GetIndexerInfo(type, indexerParameterType, allowPrivateMembers: false); - indexerInfo ??= GetIndexerInfo(type, null, allowPrivateMembers: false); + var indexerInfo = GetIndexerInfo(type, indexerParameterType, allowPrivateMembers: allowPrivateMembers); + indexerInfo ??= GetIndexerInfo(type, null, allowPrivateMembers: allowPrivateMembers); if (indexerInfo != null) { @@ -327,7 +327,7 @@ private static bool InternalIsEvent(Type type, string property) } } - var propertyInfo = GetPropertyInfo(type, property, allowPrivateMembers: false); + var propertyInfo = GetPropertyInfo(type, property, allowPrivateMembers: allowPrivateMembers); if (propertyInfo != null) {