Skip to content

Commit

Permalink
Handle nested BindingNotifications.
Browse files Browse the repository at this point in the history
When #13970 was written, [a check](https://github.com/AvaloniaUI/Avalonia/pull/13970/files#diff-cfb25a491b9452e1815aa2c0d71465aaf81e99792a88a04a1a2ed572fd1930ffR60) was added to ensure that nested `BindingNotification`s didn't happen, and the refactor was written with the assumption that they wouldn't happen.

The problem is that they _do_ happen: when a source object implements both `INotifyDataErrorInfo` and had data annotations, then the nested data validation plugins would each wrap the value coming from the previous plugin in a new `BindingNotification`, resulting in nested `BindingNotifications`.

This adds support for nested binding notifications back in - even though IMO nesting binding notifications is a bug, if we're doing it and we previously supported it then we should continue to support it.

Fixes #15201
  • Loading branch information
grokys committed May 14, 2024
1 parent c9a8d1a commit 3af6d2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/Avalonia.Base/Data/BindingNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class BindingNotification
/// <param name="value">The binding value.</param>
public BindingNotification(object? value)
{
Debug.Assert(value is not BindingNotification);
_value = value;
}

Expand Down
11 changes: 9 additions & 2 deletions src/Avalonia.Base/Data/Core/ExpressionNodes/ExpressionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,20 @@ protected void SetValue(object? valueOrNotification)
else if (notification.ErrorType == BindingErrorType.DataValidationError)
{
if (notification.HasValue)
SetValue(notification.Value, notification.Error);
{
if (notification.Value is BindingNotification n)
SetValue(n);
else
SetValue(notification.Value, notification.Error);
}
else
{
SetDataValidationError(notification.Error!);
}
}
else
{
SetValue(notification.Value, null);
SetValue(notification.Value);
}
}
else
Expand Down

0 comments on commit 3af6d2b

Please sign in to comment.