54 lines
1.6 KiB
C#
54 lines
1.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Avalonia;
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
using Avalonia.Data.Core.Plugins;
|
|
using Avalonia.Markup.Xaml;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Nebula.Launcher.Views;
|
|
using Nebula.Shared;
|
|
|
|
namespace Nebula.Launcher;
|
|
|
|
public class App : Application
|
|
{
|
|
private IServiceProvider _serviceProvider = null!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddAvaloniaServices();
|
|
services.AddServices();
|
|
services.AddViews();
|
|
|
|
_serviceProvider = services.BuildServiceProvider();
|
|
|
|
switch (ApplicationLifetime)
|
|
{
|
|
case IClassicDesktopStyleApplicationLifetime desktop:
|
|
DisableAvaloniaDataAnnotationValidation();
|
|
desktop.MainWindow = _serviceProvider.GetService<MainWindow>();
|
|
break;
|
|
case ISingleViewApplicationLifetime singleViewPlatform:
|
|
singleViewPlatform.MainView = _serviceProvider.GetRequiredService<MainView>();
|
|
break;
|
|
}
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
}
|
|
|
|
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);
|
|
}
|
|
} |