elfisa-pharmacy/src/Elfisa.Avalonia/App.axaml.cs
Exest c808d62188 версия 2.0.8: выбор шрифта интерфейса в Настройках
- Настройки: выпадающий список «Шрифт» со всеми системными шрифтами
  (+ «По умолчанию»), с превью каждого шрифта в себе самом
- шрифт применяется ко всему приложению (ресурс AppFontFamily + стиль Window),
  сохраняется и восстанавливается при старте

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-13 16:21:00 +03:00

49 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using System.Linq;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Elfisa.Avalonia.ViewModels;
using Elfisa.Avalonia.Views;
namespace Elfisa.Avalonia;
public partial class App : Application
{
/// <summary>Дефолтный шрифт интерфейса (когда «По умолчанию»).</summary>
public const string DefaultFont = "Segoe UI";
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
/// <summary>Применяет шрифт ко всему приложению (ресурс наследуется всеми окнами).</summary>
public static void ApplyFont(string? name)
{
var family = string.IsNullOrWhiteSpace(name) ? DefaultFont : name!;
if (Current is { } app)
app.Resources["AppFontFamily"] = new FontFamily(family);
}
public override void OnFrameworkInitializationCompleted()
{
RequestedThemeVariant = Elfisa.Core.SettingsStore.Current.Theme == "Dark"
? global::Avalonia.Styling.ThemeVariant.Dark
: global::Avalonia.Styling.ThemeVariant.Light;
ApplyFont(Elfisa.Core.SettingsStore.Current.FontFamily);
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new RootViewModel(),
};
}
base.OnFrameworkInitializationCompleted();
}
}