Skip to content

Fix data validation errors not showing for OneWayToSource bindings - #22103

Merged
MrJul merged 3 commits into
mainfrom
fix-8235-onewaytosource-validation
Aug 31, 2026
Merged

MrJul merged 3 commits into
mainfrom
fix-8235-onewaytosource-validation

Conversation

@grokys

@grokys grokys commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

What does the pull request do?

Fixes #8235. Data validation errors (from validation attributes such as [MaxLength]/[Required], or INotifyDataErrorInfo) were not displayed when a control was bound with Mode=OneWayToSource.

Also fixes #15378.

What is the current behavior?

When writing a value to the source of a OneWayToSource binding, BindingExpression.OnNodeValueChanged gated all publishing back to the target on _mode != BindingMode.OneWayToSource. That correctly avoids pushing a value to the target, but it also silently discarded any data validation error produced by the source-property write, so no error was ever surfaced on the control.

What is the updated behavior?

For OneWayToSource bindings with data validation enabled, the validation error is now published (and cleared) via PublishValue(UnchangedValue, error). Because the value is UnchangedValue, hasValueChanged is false and no value is pushed back to the target — preserving one-way-to-source semantics — while hasErrorChanged still routes the error to the target's data validation. This is the same mechanism already used by OnDataValidationError.

Tests

Added tests in BindingExpressionTests.DataValidation.cs covering both the DataAnnotations ([MaxLength], the exact scenario from the issue) and INotifyDataErrorInfo cases, asserting the error appears on invalid input and clears on valid input. These fail on main and pass with the fix.

  • New *OneWayToSource* tests: pass (Reflection + Compiled binding variants)
  • Avalonia.Base.UnitTests: 3378 passed, 12 skipped, 0 failed
  • Avalonia.Markup.UnitTests: 252 passed
  • Avalonia.Markup.Xaml.UnitTests binding tests: 262 passed

🤖 Generated with Claude Code

grokys and others added 2 commits August 30, 2026 13:38
Data validation errors from validation attributes (e.g. [MaxLength]) and
INotifyDataErrorInfo are not displayed when binding with
Mode=OneWayToSource. Add tests covering both the DataAnnotations and INDEI
cases when writing to the source.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013gwdaykrFyoMZFeVmWMydb
In OneWayToSource mode, BindingExpression.OnNodeValueChanged discarded any
data validation error produced when writing the value to the source, so
validation attributes and INotifyDataErrorInfo errors were never displayed.

Publish (and clear) the error via UnchangedValue so that the error state
reaches the target without pushing a value back to it, preserving the
one-way-to-source semantics.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013gwdaykrFyoMZFeVmWMydb
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0069157-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@rabbitism

Copy link
Copy Markdown
Contributor

Could you please also check on this

#15378

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@grokys

grokys commented Aug 30, 2026

Copy link
Copy Markdown
Member Author

@rabbitism checked, and this PR fixes that issue too. Added a passing unit test.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0069161-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added the backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch label Aug 31, 2026

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MrJul
MrJul added this pull request to the merge queue Aug 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 31, 2026
@grokys
grokys added this pull request to the merge queue Aug 31, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 31, 2026
@MrJul
MrJul added this pull request to the merge queue Aug 31, 2026
Merged via the queue into main with commit 31d6979 Aug 31, 2026
11 checks passed
@MrJul
MrJul deleted the fix-8235-onewaytosource-validation branch August 31, 2026 11:50
MrJul pushed a commit to MrJul/Avalonia that referenced this pull request Sep 2, 2026
…valoniaUI#22103)

* Add failing tests for OneWayToSource validation (AvaloniaUI#8235)

Data validation errors from validation attributes (e.g. [MaxLength]) and
INotifyDataErrorInfo are not displayed when binding with
Mode=OneWayToSource. Add tests covering both the DataAnnotations and INDEI
cases when writing to the source.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013gwdaykrFyoMZFeVmWMydb

* Publish data validation errors for OneWayToSource bindings (AvaloniaUI#8235)

In OneWayToSource mode, BindingExpression.OnNodeValueChanged discarded any
data validation error produced when writing the value to the source, so
validation attributes and INotifyDataErrorInfo errors were never displayed.

Publish (and clear) the error via UnchangedValue so that the error state
reaches the target without pushing a value back to it, preserving the
one-way-to-source semantics.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013gwdaykrFyoMZFeVmWMydb

* Added passing test for AvaloniaUI#15378.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants