App.axaml.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using ApplicationAvalonia.ViewModels;
  2. using ApplicationAvalonia.Views;
  3. using Avalonia;
  4. using Avalonia.Controls.ApplicationLifetimes;
  5. using Avalonia.Data.Core;
  6. using Avalonia.Data.Core.Plugins;
  7. using Avalonia.Markup.Xaml;
  8. namespace ApplicationAvalonia
  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. }