Skip to content

Commit

Permalink
fix(xbind): Fix x:Bind not working properly for private properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 22, 2023
1 parent 2d41b61 commit 425aedd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<TextBlock x:Name="_InstanceProperty"
x:FieldModifier="public"
Text="{x:Bind InstanceProperty}" />
<TextBlock x:Name="_PrivateInstanceProperty"
x:FieldModifier="public"
Text="{x:Bind PrivateInstanceProperty, Mode=OneWay}" />
<TextBlock x:Name="_StaticProperty"
x:FieldModifier="public"
Text="{x:Bind local:Functions_Control.StaticProperty}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public Functions_Control()
this.InitializeComponent();
}

private int PrivateInstanceProperty => 41;

public int InstanceProperty => 42;

public static int StaticProperty => 43;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/Uno.UI/DataBinding/BindingPropertyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down

0 comments on commit 425aedd

Please sign in to comment.