Open duongphuhiep opened 3 months ago
OR the template should simply follow the official documentation
private void DisableAvaloniaDataAnnotationValidation()
{
// Get an array of plugins to remove
var dataValidationPluginsToRemove =
BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
// remove each entry found
foreach (var plugin in dataValidationPluginsToRemove)
{
BindingPlugins.DataValidators.Remove(plugin);
}
}
public override void OnFrameworkInitializationCompleted()
{
// Avoid duplicate validations from both Avalonia and CT. More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
DisableAvaloniaDataAnnotationValidation();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}
base.OnFrameworkInitializationCompleted();
}
I think DataAnnotationsValidationPlugin was made internal at some point temporary, and then was reverted. Which is why templates are changed, but documentation wasn't.
PRs are welcomed to change it back in the templates.
Is your feature request related to a problem? Please describe.
The value 0 is too "magic" IMO, if we upgrade the Avalonia version then the value 0 might not apply and might cause unwanted regression.
https://github.com/AvaloniaUI/avalonia-dotnet-templates/blob/7d00e7b665d9ccc80e8c7f621ec66204253d2e6d/templates/csharp/app-mvvm/App.axaml.cs#L27
Describe the solution you'd like
Replace the 0 with something less magic which stand more chance for future Avalonia update.
Describe alternatives you've considered
Find a way in avalonia or CT to disable this validation by configuration, instead of adding it then removing it.
Additional context
No response