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
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
BindingPlugins.DataValidators.RemoveAt(0);
Describe the solution you'd like
Replace the 0 with something less magic which stand more chance for future Avalonia update.
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
BindingPlugins.DataValidators.Remove(BindingPlugins.DataValidators.First(plugin => plugin is DataAnnotationsValidationPlugin));
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
The text was updated successfully, but these errors were encountered:
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.
avalonia-dotnet-templates/templates/csharp/app-mvvm/App.axaml.cs
Line 27 in 7d00e7b
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
The text was updated successfully, but these errors were encountered: