Vizual_Zurnal/Zurnal_Vizual/App.axaml.cs

50 lines
1.6 KiB
C#
Raw Normal View History

2024-12-06 07:26:58 +00:00
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
2024-12-09 10:41:40 +00:00
using Microsoft.Extensions.DependencyInjection;
using Presence.Desktop.DI;
using Presence.Desktop.ViewModels;
using System.Linq;
2024-12-06 07:26:58 +00:00
namespace Zurnal_Vizual
{
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
2024-12-09 10:41:40 +00:00
var servisCollect = new ServiceCollection();
servisCollect.AddCommonService();
var sesrvis = servisCollect.BuildServiceProvider();
var mainViewModel = sesrvis.GetRequiredService<MainWindowViewModel>();
2024-12-06 07:26:58 +00:00
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
DisableAvaloniaDataAnnotationValidation();
2024-12-09 10:41:40 +00:00
desktop.MainWindow = new MainWindow
2024-12-06 07:26:58 +00:00
{
2024-12-09 10:41:40 +00:00
DataContext = mainViewModel,
2024-12-06 07:26:58 +00:00
};
}
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);
}
}
}
}