dotnet
dotnet copied to clipboard
ObservableValidator and inheritance
Describe the bug
I noticed that if my VM is part of an inheritance hierarchy the validation doesn't work.
E.g. I have this structure:
ChildVM: BaseVM
BaseVM: ObservableObject
In my child VM, I call the Save method in the base VM. The base VM then calls ValidateAllProperties. The result is always false for HasErrors.
If I pull all the code up into the child VM it works ok, so I am confident the code itself is right.
Is this expected behaviour, and if so what do I need to make it work?
Regression
No response
Steps to reproduce
public partial class BaseVm: ObservableValidator
{
[Required(AllowEmptyStrings = false, ErrorMessage = "Firstname required")]
[ObservableProperty]
public string _contact1Name;
public async Task<bool> SaveContacts()
{
bool result = false;
try
{
ValidateAllProperties();
if (HasErrors) // ** Always false **
{
//....
}
}
}
public partial class SupportVm : BaseVm
{
[RelayCommand]
public async Task<bool> NextButtonPressed()
{
bool result = await base.Save();
// ....
}
}
Expected behavior
If the required property is blank an HasErrors should be true.
Screenshots
No response
IDE and version
VS 2022
IDE version
Version 17.5.4
Nuget packages
- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.1.0
Additional context
No response
Help us help you
No, just wanted to report this
Hi there
I cannot reproduce this bug. Works like a charm here.
I suggest to close this issue.
best regards