From aa46bb5e91a4eaf24f89b7fe6950715f5ecee169 Mon Sep 17 00:00:00 2001 From: Bartosz Korczynski Date: Thu, 14 Nov 2024 00:12:57 +0000 Subject: [PATCH] fix: custom fonts in font dialog --- Directory.Build.props | 2 +- .../Dialogs/Font/FontDialogViewModel.cs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 308139d..44b562c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,7 +2,7 @@ 11.2.0 - 11.2.0.5 + 11.2.0.6 11.2.0 diff --git a/src/Classic.CommonControls.Avalonia/Dialogs/Font/FontDialogViewModel.cs b/src/Classic.CommonControls.Avalonia/Dialogs/Font/FontDialogViewModel.cs index ca7f2ee..bccb19f 100644 --- a/src/Classic.CommonControls.Avalonia/Dialogs/Font/FontDialogViewModel.cs +++ b/src/Classic.CommonControls.Avalonia/Dialogs/Font/FontDialogViewModel.cs @@ -11,14 +11,14 @@ public class FontDialogViewModel : INotifyPropertyChanged public ObservableCollection FontStyles { get; } = new(); public List FontSizes { get; } = new() { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 }; - private FontFamily? selectedFont; - public FontFamily? SelectedFont + private FontFamily selectedFont; + public FontFamily SelectedFont { get => selectedFont; set { SetField(ref selectedFont, value); - SetField(ref fontNameText, value?.Name, nameof(FontNameText)); + SetField(ref fontNameText, value.Name, nameof(FontNameText)); UpdateFontStyles(); } } @@ -37,8 +37,8 @@ public double SelectedFontSize set => SetField(ref selectedFontSize, value); } - private string? fontNameText; - public string? FontNameText + private string fontNameText; + public string FontNameText { get => fontNameText; set @@ -68,7 +68,13 @@ public FontDialogViewModel(FontDialogResult? initial) : this() if (initial == null) return; - selectedFont = Fonts.FirstOrDefault(x => x == initial.Family) ?? Fonts.FirstOrDefault(); + if (Fonts.FirstOrDefault(x => x == initial.Family) is { } font) + selectedFont = font; + else + { + Fonts.Add(initial.Family); + selectedFont = initial.Family; + } UpdateFontStyles(); selectedFontSize = initial.Size; selectedFontStyle = FontStyles.FirstOrDefault(x => x.FontWeight == initial.Weight && x.FontStyle == initial.Style);