You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a DirectProperty that is bound to an ObservableObject's property in my project. Here is an example of a DirectProperty implementing some custom logic in its setter. I expect the setter code to run whenever the ObservableObject raises a PropertyChanged event, but that only happens when newValue does not equal oldValue according to the default IEqualityComparer. I know that because my custom logic does not run. In fact, I suspect that the value held by the backing field does not even get used.
public static readonly DirectProperty<ControlWithDirectProperty, string?> DirectValueProperty =
AvaloniaProperty.RegisterDirect<ControlWithDirectProperty, string?>(nameof(DirectValue), o => o.DirectValue, (o, e) => o.DirectValue = e);
public string? DirectValue
{
get => _directValue;
set
{
/* some custom logic */
SetAndRaise(DirectValueProperty, ref _directValue, value);
}
}
private string? _directValue;
To Reproduce
Create a control with a DirectProperty that has a binding and some custom logic in the setter. Raise the PropertyChanged event in the binding source while not giving a different new value. See that the custom setter logic does not execute. You can download my sample project to test it out. AvaloniaDirectPropertyTest.zip
Expected behavior
The DirectProperty's setter should be executed regardless of what the new value is. Equality check should be done by comparing the new value against the backing field, and the decision to update the value and raise PropertyChanged event should be done within the SetAndRaise method.
Avalonia version
11.2.3
OS
Windows
Additional context
The documentation states that Avalonia DirectProperty "expose a standard C# property as an Avalonia property", and that the "property setter is a standard C# property setter that raises an event". Equality check should be done by comparing against the backing field within DirectProperty's setter SetAndRaise method, as written in the source code, to ensure that the user has full control over how the property is set and get, and that any custom logic is respected. How can I ensure that the setter code for my property is always executed?
The text was updated successfully, but these errors were encountered:
Describe the bug
I have a DirectProperty that is bound to an ObservableObject's property in my project. Here is an example of a DirectProperty implementing some custom logic in its setter. I expect the setter code to run whenever the ObservableObject raises a PropertyChanged event, but that only happens when newValue does not equal oldValue according to the default IEqualityComparer. I know that because my custom logic does not run. In fact, I suspect that the value held by the backing field does not even get used.
To Reproduce
Create a control with a DirectProperty that has a binding and some custom logic in the setter. Raise the PropertyChanged event in the binding source while not giving a different new value. See that the custom setter logic does not execute. You can download my sample project to test it out.
AvaloniaDirectPropertyTest.zip
Expected behavior
The DirectProperty's setter should be executed regardless of what the new value is. Equality check should be done by comparing the new value against the backing field, and the decision to update the value and raise PropertyChanged event should be done within the SetAndRaise method.
Avalonia version
11.2.3
OS
Windows
Additional context
The documentation states that Avalonia DirectProperty "expose a standard C# property as an Avalonia property", and that the "property setter is a standard C# property setter that raises an event". Equality check should be done by comparing against the backing field within DirectProperty's setter SetAndRaise method, as written in the source code, to ensure that the user has full control over how the property is set and get, and that any custom logic is respected. How can I ensure that the setter code for my property is always executed?
The text was updated successfully, but these errors were encountered: