New to Telerik UI for WPF? Download free 30-day trial

Setting the FontSize in C# when a Telerik theme is applied

Environment

Product Version 2020.2.513
Product RadGridView for WPF

Description

How to set a different font size in C# for themes which support palettes.

Solution

When using any of the Telerik themes which support palettes (the ones with the links from the list), you can dynamically change the FontSize and FontFamily properties of all components in the application.

Most controls use the theme Palette's FontSize property, yet all themes support a different number of various font sizes. For example, if the Office2016Theme is applied to your application, you can change the following font size properties of its palette:

Example 1: Modifying the FontSize and FontFamily in the Office2016 theme

Office2016Palette.Palette.FontSizeS = 10;  
Office2016Palette.Palette.FontSize = 12;  
Office2016Palette.Palette.FontSizeL = 14; 
Office2016Palette.Palette.FontFamily = new FontFamily("Segoe UI");  
The values assigned to the Palette's font size properties are the default ones. You can change them on a click of a button as well at run-time. The following Example 2 how to change the default FontFamily from "Segoe UI" to "Calibri" and the FontSize from 12 to 14.

Example 2: Changing the default FontSize and FontFamily in the Office2016 theme on a button click

private void OnButtonChangeFontSizeClick(object sender, RoutedEventArgs e)  
{  
    Office2016Palette.Palette.FontSize = 14;  
    Office2016Palette.Palette.FontFamily = new FontFamily("Calibri");  
}  

Figure 1: Setting different FontSize and FontFamily

The approach used in the above code snippets is applicable for the following themes - Windows8, Windows8Touch, Office2013, VisualStudio2013, Office2016, Office2016Touch, Green, Fluent, Material, Crystal and VisualStudio2019.

If you are using a different theme, which does not have a palette, you can change the font size of the application through Application.Current.MainWindow.FontSize or apply it directly for the control you wish, e.g. this.dataGrid.FontSize = 20.

See Also

Available Themes Theme Helper Switching Themes at Runtime

In this article
Not finding the help you need? Improve this article