App.axaml.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using Avalonia;
  2. using Avalonia.Controls.ApplicationLifetimes;
  3. using Avalonia.Data.Core;
  4. using Avalonia.Data.Core.Plugins;
  5. using Avalonia.Markup.Xaml;
  6. using TestRepeat.ViewModels;
  7. using TestRepeat.Views;
  8. namespace TestRepeat
  9. {
  10. public partial class App : Application
  11. {
  12. public override void Initialize()
  13. {
  14. AvaloniaXamlLoader.Load(this);
  15. }
  16. public override void OnFrameworkInitializationCompleted()
  17. {
  18. if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
  19. {
  20. // Line below is needed to remove Avalonia data validation.
  21. // Without this line you will get duplicate validations from both Avalonia and CT
  22. BindingPlugins.DataValidators.RemoveAt(0);
  23. desktop.MainWindow = new MainWindow
  24. {
  25. DataContext = new MainWindowViewModel(),
  26. };
  27. }
  28. base.OnFrameworkInitializationCompleted();
  29. }
  30. }
  31. }