Files
XLAB/XLAB2/App.xaml.cs
Курнат Андрей a47a7a5a3b edit
2026-03-19 23:31:41 +03:00

73 lines
2.0 KiB
C#

using System;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Markup;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using XLAB2.Infrastructure;
namespace XLAB2
{
public partial class App : Application
{
private IHost _host;
public App()
{
ApplyRussianCulture();
}
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
try
{
_host = AppHost.Create();
await _host.StartAsync().ConfigureAwait(true);
MainWindow = _host.Services.GetRequiredService<MainWindow>();
MainWindow.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "XLAB2", MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown(-1);
}
}
protected override async void OnExit(ExitEventArgs e)
{
if (_host != null)
{
try
{
await _host.StopAsync(TimeSpan.FromSeconds(5)).ConfigureAwait(true);
}
finally
{
_host.Dispose();
}
}
base.OnExit(e);
}
private static void ApplyRussianCulture()
{
var culture = new CultureInfo("ru-RU");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(culture.IetfLanguageTag)));
}
}
}