Repository navigation
Fix data validation errors not showing for OneWayToSource bindings - #22103
Merged
Merged
Conversation
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
|
You can test this PR using the following package version. |
Contributor
|
Could you please also check on this |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
Author
|
@rabbitism checked, and this PR fixes that issue too. Added a passing unit test. |
|
You can test this PR using the following package version. |
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Aug 31, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Aug 31, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
Fixes #8235. Data validation errors (from validation attributes such as
[MaxLength]/[Required], orINotifyDataErrorInfo) were not displayed when a control was bound withMode=OneWayToSource.Also fixes #15378.
What is the current behavior?
When writing a value to the source of a
OneWayToSourcebinding,BindingExpression.OnNodeValueChangedgated 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
OneWayToSourcebindings with data validation enabled, the validation error is now published (and cleared) viaPublishValue(UnchangedValue, error). Because the value isUnchangedValue,hasValueChangedis false and no value is pushed back to the target — preserving one-way-to-source semantics — whilehasErrorChangedstill routes the error to the target's data validation. This is the same mechanism already used byOnDataValidationError.Tests
Added tests in
BindingExpressionTests.DataValidation.cscovering both the DataAnnotations ([MaxLength], the exact scenario from the issue) andINotifyDataErrorInfocases, asserting the error appears on invalid input and clears on valid input. These fail onmainand pass with the fix.*OneWayToSource*tests: pass (Reflection + Compiled binding variants)Avalonia.Base.UnitTests: 3378 passed, 12 skipped, 0 failedAvalonia.Markup.UnitTests: 252 passedAvalonia.Markup.Xaml.UnitTestsbinding tests: 262 passed🤖 Generated with Claude Code