57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using System;
|
|
using System.ComponentModel.Design;
|
|
using Avalonia;
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
using Avalonia.Data.Core;
|
|
using Avalonia.Data.Core.Plugins;
|
|
using System.Linq;
|
|
using Avalonia.Markup.Xaml;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using PantherByte.Services;
|
|
using PantherByte.Services.Interfaces;
|
|
using PantherByte.ViewModels;
|
|
using PantherByte.Views;
|
|
|
|
namespace PantherByte;
|
|
|
|
public partial class App : Application {
|
|
/// <summary>
|
|
/// The services that are available for the application.
|
|
/// </summary>
|
|
public IServiceProvider? Services { get; private set; }
|
|
|
|
public new static App? Current => Application.Current as App;
|
|
|
|
public override void Initialize() {
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
public override void OnFrameworkInitializationCompleted() {
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
|
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
|
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
|
DisableAvaloniaDataAnnotationValidation();
|
|
desktop.MainWindow = new MainWindow {
|
|
DataContext = new MainWindowViewModel()
|
|
};
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddSingleton<IFileSaveService>(x => new FileService(desktop.MainWindow));
|
|
|
|
Services = services.BuildServiceProvider();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |