Repository navigation
feat: Add WinUI-shaped input validation - #24838
Conversation
WinAppSDK sync generator drift detected on
|
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24838/docs/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24838/wasm-skia-net9/index.html |
|
The build 236518 found UI Test snapshots differences: Details
|
92c127f to
80a2860
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24838/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24838/docs/index.html |
|
The build 236733 found UI Test snapshots differences: Details
|
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24838/docs/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24838/wasm-skia-net9/index.html |
|
The build 236770 found UI Test snapshots differences: Details
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24838/wasm-skia-net9/index.html |
|
The build 237007 found UI Test snapshots differences: Details
|
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24838/docs/index.html |
|
|
1630679 to
8b8ebbd
Compare
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24838/wasm-skia-net9/index.html |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24838/docs/index.html |
|
The build 237533 found UI Test snapshots differences: Details
|
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24838/docs/index.html |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24838/wasm-skia-net9/index.html |
|
The build 237558 found UI Test snapshots differences: Details
|
The handlers and the subscription lived in attached dependency properties, a leftover from when a separate Validation class owned them. A single lazily-created state object on Control now holds them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The validation surface no longer lives on the WinUI types. The Mode, Kind, ErrorTemplate, HasErrors and Errors properties are now attached properties on Uno.Extras.Input.Validation, in Uno.UI.Extras. On WinAppSDK their handlers are compiled out. - IInputValidationControl is deleted, along with the per-control DPs and the HasValidationErrorsChanged, ValidationError and ErrorChanged events. The HasValidationErrorsChangedEventArgs stub is restored. - InputValidationMode, InputValidationKind and InputValidationError move to Uno.Extras.Input and are compile-linked into Uno.UI.Extras.Windows. - The engine stays on Control. It reads the attached DPs through an internal slot that Validation's static constructor fills, and a control participates through its validation property alone. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Validation.Errors is created empty and then filled in place, so a converter bound to it ran once on the empty collection and the sample never showed an error. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Uno.UI.Extras is an assembly split, not a namespace root: its types live under Uno.UI.*, so Uno.Extras.Input becomes Uno.UI.Xaml.Controls. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Template application ran a ValidationDisabled GoToState on every templated control, even with input validation turned off globally. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The docs said an app may add its own errors, but every sync with the source replaces the contents, so an added error is gone at the next keystroke. Document that behavior and pin it with a test. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Master now requires [UITestClass] on every unit test class. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
DefaultCompactErrorIconTemplate is resolved at the application level, so an app can replace it from Application.Resources. The spec also still placed it in SystemResources.xaml, where master no longer defines it. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A misspelled [InputValidationProperty] silently opted the control out. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
009b620 to
8655809
Compare
|
Thanks for the review. Branch rebased on master, and here's what happened to each finding:
|
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
|
🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-24838/docs/index.html |
|
The build 240213 found UI Test snapshots differences: Details
|
|
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
- Phase A: Simple input styles gain validation visuals against the local validation build - Phase B: temporary Validation shim until unoplatform/uno#24838 ships Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…noplatform/uno#24838 - Uno.Extras.Input.Validation (Mode, Kind, ErrorTemplate, HasErrors, Errors), InputValidationKind/Mode and InputValidationError, with the framework's API surface - Mirrors INotifyDataErrorInfo errors of a single-segment {Binding} onto the control and drives the InputValidation* visual states and ErrorPresenter part - Uno-only (HAS_UNO); lives in Uno.Themes.WinUI because the shared sample page compiles into every head - SimpleSampleApp no longer sets FeatureConfiguration.InputValidation (absent without the framework implementation); left as a TODO - To be deleted when bumping to the Uno version that ships unoplatform/uno#24838 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
- unoplatform/uno#24838 shipped in the Uno build master already uses (7.1.0-dev.477), as Uno.UI.Xaml.Controls.Validation - Point the styles, the sample page and the runtime tests at Uno.UI.Xaml.Controls instead of the temporary Uno.Extras.Input stand-in - Enable FeatureConfiguration.InputValidation in SimpleSampleApp, before the first binding is registered - The tests alias the validation types: Uno.UI.Xaml.Controls also declares a ComboBox Co-Authored-By: Claude Opus 5.5 <[email protected]>
GitHub Issue: closes #4839, related: unoplatform/uno-private#2384
PR Type:
✨ Feature
What changed? 🚀
Before: Neither WinUI nor Uno supports input validation.
INotifyDataErrorInfoworks in the BCL, but nothing carries its errors from a binding source to the bound control. Apps have to build the whole presentation layer themselves.After: Controls can opt in to input validation. Errors from an
INotifyDataErrorInfosource reach the bound control'sValidation.HasErrors/Validation.Errorsattached properties, and drive WinUI's validation visual states and error presenter. The user-facing article isdoc/articles/features/input-validation.md. Design and rationale are inspecs/059-input-validation/spec.md(transport and read model) andspecs/060-input-validation-presentation/spec.md(visuals). §10/§10b of 059 record where the implementation departed from the original draft.Opt-in (off by default)
Validation is off unless both switches are set. With the global flag off, neither the binding registration path nor template application does extra work.
Validation.Modedefaults toDisabledrather than WinUI'sAuto, because here it also gates theINotifyDataErrorInfosubscription.Transport
SetBindingInternaloverloads converge. Resolution runs onBindingExpression.OnValueChanged, which both{Binding}and{x:Bind}go through. The leaf source is read from the compiled binding's update sources as well as the binding path, so the two binding kinds behave the same (avoiding microsoft-ui-xaml#4642).ErrorsChangedis subscribed weakly, so a view model cannot keep a control alive. A raise from another thread is dispatched to the UI thread. Teardown hooksClearBinding, which covers rebinding andClearValue.Control(Control.Validation*.cs), where WinUI keeps the equivalent (CControl::IsValidationEnabled/EnsureValidationVisuals).Validation.Errorsmirrors the source: each synchronization replaces its contents in place (same collection instance), so errors an app adds itself do not survive the next one.New public API (needs API review)
Uno.UI.Xaml.Controls.Validation(inUno.UI.Extras): attachedMode,Kind,ErrorTemplate,HasErrors(read-only),Errors(read-only, created on demand). The WinAppSDK build ofUno.UI.Extrasregisters the same properties but nothing reads them, so markup stays portable.Uno.UI.Xaml.Controls(inUno.UI):InputValidationMode,InputValidationKind,InputValidationError,InputValidationPropertyAttribute,InputValidationPropertyMap.Uno.UI.FeatureConfiguration.InputValidation:IsEnabled,ValidationProperties.Control.UpdateValidationStates(): a new protected member onControl, inherited by every subclass. It lets a control outside Uno.UI re-apply the validation states from its own visual-state code.Uno.UI.Tests.ViewLibrary(not covered byInternalsVisibleTo) contains such a control, so the build fails if that contract regresses.WinUI parity
"WinUI-shaped" means the visual state groups and state names, the
ErrorPresentertemplate part,DefaultCompactErrorIconTemplate, and the member order of the enums. It does not mean the API:IInputValidationControl,InputValidationContext,InputValidationErrorEventArgsand theValidationError/HasValidationErrorsChangedevents are not ported. They live in WinUI's private IDL (PrivateApiContract/Feature_InputValidation), which has never shipped. Change notification onValidation.HasErrorsandVectorChangedonValidation.Errorstake their place.Uno.UI.Xaml.Controls, notMicrosoft.UI.Xaml.Controls, so they cannot collide if microsoft-ui-xaml#179 ships with a different shape.HasValidationErrorsChangedEventArgskeeps its[Uno.NotImplemented]generated stub.ComboBoxvalidatesSelectedItem(see below),Modedefaults toDisabled,Defaultcounts as enabled, and there is noTryDefer.Participants
The participants are WinUI's four:
TextBox→Text,PasswordBox→Password,AutoSuggestBox→Text,ComboBox→SelectedItem.ComboBoxdeparts from WinUI, which validatesText: a non-editableComboBoxis bound onSelectedItem, so validatingTextwould leave the common case with no errors. Any other control opts in with[InputValidationProperty]or aValidationPropertiesregistration. A misspelled attribute name logs a warning.Presentation (spec 060, partial)
InputValidationEnabledStates/InputValidationErrorStatesare applied when the errors,Validation.ModeorValidation.Kindchange, and when the template is applied.CControl::EnsureErrors/DeferErrors: the first error realizes the template'sErrorPresenter, which showsErrorTemplateinline, or in the tooltip ofDefaultCompactErrorIconTemplatefor compact mode. An app can replace that icon fromApplication.Resources.CommonStatescontention (060 §3 / Q10). The shipped Fluent templates don't have validation parts yet, so nothing appears on screen unless the app's template or markup renders it.Related fix
fix: Resolve attached properties of uninitialized owners(7177194):DependencyPropertyDescriptor.Parseredirected a parenthesized path to the owner type without running that type's static constructor. The lookup missed and the miss was cached, so{Binding (Owner.Property)}read the initial value once and never updated. This affectedCanvas.Lefttoo.Tests & sample
Uno.UI.UnitTests/InputValidation/): transport, the property map, public surface guard, a third-party control, attached-path resolution, and the feature-off template path.Uno_UI_Xaml_Controls/InputValidation/): validation visual states (including errors raised off the UI thread) and the error presenter (including an app-level icon override).Uno/UI/Xaml/Controls/Validation/InputValidation. It turns the global flag on in its own constructor; the rest of the SamplesApp runs with the feature off.PR Checklist ✅
Screenshots Compare Test Runresults.feat!/refactor!commits only break API added earlier in this branch, which has never been released. Compared withmaster, the changes are additive and off by default.🤖 Generated with Claude Code