-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The new MVVM-Toolkit got some new bugs with the latest updated. #3763
Comments
Hello timunie, thank you for opening an issue with us! I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌 |
Hey @timunie, thanks for the report! This is interesting, I'll take a look! |
Small update, I've identified and fixed the first issue. Here's the breakdown of what was causing it, for future reference. The fix is to just load and cache the Still investigating the other issue... |
Hey @timunie, I'm a bit confused with respect to issue 2 and need some more info to investigate this 🙂 I can repro that with Preview 4 as well, it doesn't seem to be something new in the new version. This is the internal state of the viewmodel right after the call to |
Hi @Sergio0694 , The second one is indeed very strange. It still counts two times and if I change the error-template it also tells me two errors where I see in the source only one. Maybe this is a bug in WPF itself. Let me ask @punker76 if he knows this issue in wpf. Anyway thank you for your support and have a nice weekend. Tim |
Yeah that issue is weird, curious to see if anyone else has experienced that on WPF with another |
My old implementation has the same issue. I just never did classlevel validation before so I never noticed that. If you want to close the issue you are free to do so. |
Ah, thanks for the additional info! No need to close this issue, it will automatically be closed when #3764 is merged, since that fixes issue 1 here 😄 |
Hi @Sergio0694 I think I found a solution for issue 2. But unfortunately it cannot be implemented in my App 😒 . I have either to use my own MVVM library again or you need to help me another time 🙏 . What I found out is, that
Since the check is /// <inheritdoc cref="INotifyDataErrorInfo.GetErrors(string)"/>
[Pure]
public IEnumerable<ValidationResult> GetErrors(string? propertyName = null)
{
// Get entity-level errors when the target property is null or empty
if (propertyName == string.Empty) // modified this line
{
// Local function to gather all the entity-level errors
[Pure]
[MethodImpl(MethodImplOptions.NoInlining)]
IEnumerable<ValidationResult> GetAllErrors()
{
return this.errors.Values.SelectMany(static errors => errors);
}
return GetAllErrors();
}
// Property-level errors, if any
if (propertyName is not null && this.errors.TryGetValue(propertyName!, out List<ValidationResult>? errors)) // we need to perform additional null-check here.
{
return errors;
}
// The INotifyDataErrorInfo.GetErrors method doesn't specify exactly what to
// return when the input property name is invalid, but given that the return
// type is marked as a non-nullable reference type, here we're returning an
// empty array to respect the contract. This also matches the behavior of
// this method whenever errors for a valid properties are retrieved.
return Array.Empty<ValidationResult>();
} Here is the updated example: https://github.com/timunie/MvvmToolkitValidationSample/tree/Issue2/Solution-1 How would you like to track this issue?
Happy coding |
*sigh* Thanks @timunie for looking into this and confirming the issue is in fact on the WPF side! If you look at the official MS docs for the
I highlighted in bold the part that interests us here. The spec explicitly says that both I absolutely recommend opening an issue for this in the WPF repo, or just comment in an existing one if there's one already. Please include a link to this issue if you do, so we can track that as well or just refer to it should this come up again in the future. As for WinUI (and UWP XAML), from what I can tell this is properly handled already since this specific issue hasn't come up before (not that I can remember), but cc. @stevenbrix just in case this is interesting to you and/or if you want to confirm this bug is in fact not present on either frameworks (or at least WinUI 3 in particular). 😄 FYI @michael-hawker |
Hi All, I filed a bug to the wpf-team: dotnet/wpf#4201 Just in case someone is interested
Source: https://github.com/timunie/MvvmToolkitValidationSample/tree/Issue2/Solution-2 Happy coding |
## Fixes #3763 <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> - Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> - Incorrect loading of display names for validated properties - Repeated error messages after validation ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> Fixed the errors above. Opening as a draft to have the CI run, but I'm still investigating the second issue from the list above. ## PR Checklist Please check if your PR fulfills the following requirements: - [X] Tested code with current [supported SDKs](../readme.md#supported) - [ ] ~~Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->~~ - [ ] ~~Sample in sample app has been added / updated (for bug fixes / features)~~ - [ ] ~~Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)~~ - [X] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [X] Tests for the changes have been added (for bug fixes / features) (if applicable) - [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes
Short update: Issue 1 is gone now. Thank you for your effort. |
That's awesome, thank you for confirming that and for the original report! 🥳 🎉 |
Describe the bug
I am not sure if it is one bug or two. For that reason I will open only one ticket by today. If you think I should divide it I will open a second issue.
Steps to Reproduce
Steps to reproduce the behavior:
Issue 1:
ObservableValidator
in yourViewModel
The field {0} is required
and let the validator replace {0} by theDisplayName
.Issue 2;
ObservableValidator
in yourViewModel
Expected behavior
The messages should not be reused and every field should get its own message as it was in preview4. Moreover if you perform a class-level-validation every message should be displayed only one time.
Screenshots
Issue 1
Field 1:

Field 2:

Issue 2:

Environment
Additional context
The shown sample is available here: https://github.com/timunie/MvvmToolkitValidationSample
/cc @Sergio0694
The text was updated successfully, but these errors were encountered: