Font and Theme Changes at Runtime Sometimes Stop Working

0 Answers 61 Views
General Discussions
Justin
Top achievements
Rank 2
Iron
Justin asked on 20 Sep 2023, 04:08 PM | edited on 20 Sep 2023, 04:10 PM

Good day. I have functionality in my WPF application that allows the user to change the font size, font style, and theme variations at runtime, see code below. This functions perfectly when it works. 

 

The issue I am having is that when making changes to these values at runtime, the changes intermittently stop being applied. The way I understand theming is that I should be able to make these changes at runtime and they are automatically applied. Something is getting borked up causing the changes to stop being applied during runtime.

 

C#, WPF .NET 6

Theme: Office 2019

Telerik Version: 2023.1.117

I'm using the package Telerik.UI.Wpf.NetCore.Xaml for all controls. Theme packages come from No XAML.

 

// Theme Color Variation// High Contrast
Office2019Palette.LoadPreset(Office2019Palette.ColorVariation.HighContrast);

// Dark/Light Mode
if (RegistryHelper.IsWindowsDarkMode())
    Office2019Palette.LoadPreset(Office2019Palette.ColorVariation.Dark);
else
    Office2019Palette.LoadPreset(Office2019Palette.ColorVariation.Light);


// Change Font Family
Office2019Palette.Palette.FontFamily = new FontFamily(Settings.Default.FontFamily);


// Font Size
Telerik.Windows.Controls.Office2019Palette.Palette.FontSizeS = 10;
Telerik.Windows.Controls.Office2019Palette.Palette.FontSize = 12;
Telerik.Windows.Controls.Office2019Palette.Palette.FontSizeL = 14;

 

App.xaml for Telerik:

<prism:PrismApplication x:Class="Wpf.App"
                        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                        xmlns:prism="http://prismlibrary.com/">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <!-- Telerik -->
                <ResourceDictionary Source="/Telerik.Windows.Themes.Office2019;component/Themes/System.Windows.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Office2019;component/Themes/Telerik.Windows.Controls.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Office2019;component/Themes/Telerik.Windows.Controls.Input.xaml" />
                <ResourceDictionary Source="/Telerik.Windows.Themes.Office2019;component/Themes/Telerik.Windows.Controls.Navigation.xaml" />

            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</prism:PrismApplication>

 

Dinko
Telerik team
commented on 25 Sep 2023, 03:07 PM

To change the palette settings at runtime you can take a look at How to Change Theme Variation During Runtime article in our documentation. Basically, in order to properly change all palette settings you will need to reload the required resource dictionaries after the changes.

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Justin
Top achievements
Rank 2
Iron
Share this question
or