How to set/change font family and size globally in Unity?
Back in WPF I can achieve this by setting Window's OverrideMetadata() in App class's constructor.
Now in Unity, App is no where to be found. My last (experimental) project went to set FontFamily/FontSize style with almost every control in a resources dictionary, and merge it on every xaml file. This (production) project, I kinda want to avoid that.
Also I want to change font whenever user changes the display language. I have no idea how to do that...
Now in Unity, App is no where to be found. My last (experimental) project went to set FontFamily/FontSize style with almost every control in a resources dictionary, and merge it on every xaml file. This (production) project, I kinda want to avoid that.
Also I want to change font whenever user changes the display language. I have no idea how to do that...
-
sfernandez
Site Admin
- Posts: 3008
- Joined:
Re: How to set/change font family and size globally in Unity?
As FontFamily and FontSize are properties that inherit down the tree you can set them in the root of the main xaml. If you don't explicitly set those properties in control styles, then the inherited value will apply and override the entire UI.
To change the value depending on the language you can use a DynamicResource and then insert the corresponding dictionary in root Resources:
Is this something that could work for you?
To change the value depending on the language you can use a DynamicResource and then insert the corresponding dictionary in root Resources:
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
FontFamily="{DynamicResource DefaultFont}"
FontSize="{DynamicResource DefaultFontSize}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Langs/EnglishResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
...
</UserControl>
Re: How to set/change font family and size globally in Unity?
I forgot DynamicResource... How stupid I am...🤣As FontFamily and FontSize are properties that inherit down the tree you can set them in the root of the main xaml. If you don't explicitly set those properties in control styles, then the inherited value will apply and override the entire UI.
To change the value depending on the language you can use a DynamicResource and then insert the corresponding dictionary in root Resources:Is this something that could work for you?Code: Select all<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontFamily="{DynamicResource DefaultFont}" FontSize="{DynamicResource DefaultFontSize}"> <UserControl.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Langs/EnglishResources.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </UserControl.Resources> ... </UserControl>
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests