Can I set the default font using XAML?
Posted: 19 Jan 2022, 15:34
I see the included themes use MergedDictionaries, like this:
I decided I would like to change the default font face to "Segoe UI" and the default size from 15 point to 12 point, so I did this in App.xaml:
Effectively, I replaced the Fonts.xaml resources with my own, leaving everything else the same.
This does not affect the fonts for TextBlock, Button, etc. Looking in NoesisTheme.Styles.xaml, it appears that only a few controls like groupbox, tooltips and menuitems even reference these font settings.
So, I added this code to App.OnStartup, just to prove that I could affect the fonts at all:
That seems to have worked.
The problem is that this only applies to a Noesis build. If I build the same code for WPF, it does not get these settings. The result is that the WPF target, which is the best editing environment, does not look like the eventual Noesis build.
So, can I affect the default font through XAML and have it be consistent between WPF and Noesis builds?
Code: Select all
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary ResourceDictionary.Source="NoesisTheme.Brushes.LightAqua.xaml" />
<ResourceDictionary ResourceDictionary.Source="NoesisTheme.Fonts.xaml" />
<ResourceDictionary ResourceDictionary.Source="NoesisTheme.Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Code: Select all
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Noesis.GUI.Extensions;component/Theme/NoesisTheme.Brushes.LightAqua.xaml" />
<ResourceDictionary>
<FontFamily x:Key="Font.Family.Default">Segoe UI</FontFamily>
<sys:Double x:Key="Font.Size.Header">13</sys:Double>
<sys:Double x:Key="Font.Size.Normal">12</sys:Double>
<sys:Double x:Key="Font.Size.ToolTip">10</sys:Double>
</ResourceDictionary>
<ResourceDictionary Source="pack://application:,,,/Noesis.GUI.Extensions;component/Theme/NoesisTheme.Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
This does not affect the fonts for TextBlock, Button, etc. Looking in NoesisTheme.Styles.xaml, it appears that only a few controls like groupbox, tooltips and menuitems even reference these font settings.
So, I added this code to App.OnStartup, just to prove that I could affect the fonts at all:
Code: Select all
string[] fonts = new string[] { "Segoe UI", "Arial", "Segoe UI Emoji" };
Noesis.GUI.SetFontFallbacks(fonts);
Noesis.GUI.SetFontDefaultProperties(12, FontWeight.Normal, FontStretch.Normal, FontStyle.Normal);
The problem is that this only applies to a Noesis build. If I build the same code for WPF, it does not get these settings. The result is that the WPF target, which is the best editing environment, does not look like the eventual Noesis build.
So, can I affect the default font through XAML and have it be consistent between WPF and Noesis builds?