1- #nullable enable
2- using System ;
1+ using System ;
32using System . Collections . Concurrent ;
43using System . Collections . Generic ;
54using System . IO ;
65using Microsoft . Extensions . Logging ;
76using Microsoft . Graphics . Canvas . Text ;
87using Microsoft . Maui . ApplicationModel ;
98using Microsoft . Maui . Storage ;
9+ using Microsoft . UI . Xaml ;
1010using Microsoft . UI . Xaml . Media ;
1111
1212namespace Microsoft . Maui
@@ -27,6 +27,12 @@ public class FontManager : IFontManager
2727 readonly IFontRegistrar _fontRegistrar ;
2828 readonly IServiceProvider ? _serviceProvider ;
2929
30+ /// <remarks>Value is cached to avoid the performance hit of accessing <see cref="ResourceDictionary"/> many times.</remarks>
31+ FontFamily ? _defaultFontFamily ;
32+
33+ /// <remarks>Value is cached to avoid the performance hit of accessing <see cref="ResourceDictionary"/> many times.</remarks>
34+ double ? _defaultFontSize ;
35+
3036 /// <summary>
3137 /// Creates a new <see cref="EmbeddedFontLoader"/> instance.
3238 /// </summary>
@@ -40,12 +46,24 @@ public FontManager(IFontRegistrar fontRegistrar, IServiceProvider? serviceProvid
4046 }
4147
4248 /// <inheritdoc/>
43- public FontFamily DefaultFontFamily =>
44- ( FontFamily ) UI . Xaml . Application . Current . Resources [ SystemFontFamily ] ;
49+ public FontFamily DefaultFontFamily
50+ {
51+ get
52+ {
53+ _defaultFontFamily ??= ( FontFamily ) Application . Current . Resources [ SystemFontFamily ] ;
54+ return _defaultFontFamily ;
55+ }
56+ }
4557
4658 /// <inheritdoc/>
47- public double DefaultFontSize =>
48- ( double ) UI . Xaml . Application . Current . Resources [ SystemFontSize ] ;
59+ public double DefaultFontSize
60+ {
61+ get
62+ {
63+ _defaultFontSize ??= ( double ) Application . Current . Resources [ SystemFontSize ] ;
64+ return _defaultFontSize . Value ;
65+ }
66+ }
4967
5068 /// <inheritdoc/>
5169 public FontFamily GetFontFamily ( Font font )
0 commit comments