Open arivoir opened 1 month ago
It's not clear at all why this is a bug, and the issue only describes some WPF-specific behavior. You'd need to include more details on what exact change you'd expect on ObservableValidator
, and why, for this to be actionable.
Hi @Sergio0694 , please let me give more details about the context.
ObservableValidator is a class that can be used to add validation to objects and these objects can be bound to ui-controls. These controls many time auto-generate the ui based on the information in the class itself, for instance, WPF DataGrid take all the properties of the class and creates the columns out of this.
This works fine in most scenarios, but in other cases it is necessary to tweak this mechanism so the classes are bound to control seamlessly without having to write complex customizations. For this purpose exists the System.ComponentModel.DataAnnotations attributes. https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.displayattribute?view=net-8.0
In this particular case, it is the HasErrors property that should be decorated with DisplayAttribute, so when it is bound to a control this property doesn't generate ui
/// <inheritdoc/>
[Display(AutoGenerateField = false)]
public bool HasErrors => this.totalErrors > 0;
It worth noting this is not only in WPF, but any ui framework of control using System.ComponentModel.DataAnnotations, and it's probably not a bug but a feature enhancement.
@Sergio0694 I just created a PR with the fix/feature enhancement. I appreciate if you can take a look. Thanks
Describe the bug
When binding an object inheriting ObservableValidator class to a control that has auto-generation a field is created for that property.
For instance when binding to WPF DataGrid the following column appears![image](https://github.com/CommunityToolkit/dotnet/assets/17496741/1be1a7bf-17ba-4ca6-902a-3cbf41dad993)
Regression
No response
Steps to reproduce
Expected behavior
No column should be generated for the property HasErrors
Screenshots
No response
IDE and version
VS 2022
IDE version
No response
Nuget packages
Nuget package version(s)
8.2.2
Additional context
No response
Help us help you
Yes, I'd like to be assigned to work on this item