You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This interface returns the error of the ViewModel as a non generic IEnumerable. By definition, this IEnumerable can contain ANY object, not just strings. For example, the Library Microsoft.Toolkit.Mvvm implements the interface in the following way:
//// Summary:// A base class for objects implementing the System.ComponentModel.INotifyDataErrorInfo// interface. This class also inherits from Microsoft.Toolkit.Mvvm.ComponentModel.ObservableObject,// so it can be used for observable items too.publicabstractclassObservableValidator:ObservableObject,INotifyDataErrorInfo{publicboolHasErrors{get;}publiceventEventHandler<DataErrorsChangedEventArgs>?ErrorsChanged;publicIEnumerable<ValidationResult>GetErrors(string?propertyName=null);// Other methods for setting properties and validation// [ ... ]protectedvoidValidateAllProperties();protectedinternalvoidValidateProperty(object?value,[CallerMemberName]string?propertyName=null);}
This library returns an enumerable of System.ComponentModel.DataAnnotations.ValidationResult. But it could be any object.
The problem is that in the newer version of HandyControl, all input fields support Validation, but they assume the contents of the IEnumerable are strings:
To Reproduce
Implement INotifyDataErrorInfo with GetErrors returning an IEnumerable of custom error objects instead of strings and an exception will be thrown.
Environment (please complete the following information):
.net: net5
IDE vs2019
Version HandyControls 3.3.8 (I use the forked version, but I think this bug report goes here)
The text was updated successfully, but these errors were encountered:
Describe the bug
When you implement the MVVM pattern, is usual to implement the interface INotifyDataErrorInfo.
This interface returns the error of the ViewModel as a non generic
IEnumerable
. By definition, this IEnumerable can contain ANY object, not juststrings
. For example, the LibraryMicrosoft.Toolkit.Mvvm
implements the interface in the following way:This library returns an enumerable of
System.ComponentModel.DataAnnotations.ValidationResult
. But it could be any object.The problem is that in the newer version of HandyControl, all input fields support Validation, but they assume the contents of the
IEnumerable
are strings:HandyControl/src/Shared/HandyControl_Shared/Controls/Input/TextBox.cs
Lines 123 to 127 in 5dcb6dc
So, this exception is thrown, because
System.ComponentModel.DataAnnotations.ValidationResult
is not a string.The correct way, would be:
To Reproduce
Implement
INotifyDataErrorInfo
withGetErrors
returning anIEnumerable
of custom error objects instead ofstrings
and an exception will be thrown.Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: