Skip to content

Latest commit

 

History

History
66 lines (53 loc) · 3.86 KB

kb-common-setting-fontsize-of-a-control-with-telerik-theme.md

File metadata and controls

66 lines (53 loc) · 3.86 KB
title description type page_title slug position tags ticketid res_type
Setting the FontSize in C# when a Telerik theme is applied
Change the default FontSize in code-behind when a Telerik theme is applied.
how-to
Set a different FontSize which has a Telerik theme applied
kb-common-setting-fontsize-in-code-behind-for-a-telerik-theme
0
fontsize, fontfamily, theme, theming, palettes
1470081
kb

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]({%slug common-styling-appearance-available-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:

[C#] Example 1: Modifying the FontSize and FontFamily in the Office2016 theme

{{region kb-common-setting-fontsize-in-code-behind-for-a-telerik-theme-0}} Office2016Palette.Palette.FontSizeS = 10; Office2016Palette.Palette.FontSize = 12; Office2016Palette.Palette.FontSizeL = 14; Office2016Palette.Palette.FontFamily = new FontFamily("Segoe UI"); {{endregion}}

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.

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

{{region kb-common-setting-fontsize-in-code-behind-for-a-telerik-theme-1}} private void OnButtonChangeFontSizeClick(object sender, RoutedEventArgs e) { Office2016Palette.Palette.FontSize = 14; Office2016Palette.Palette.FontFamily = new FontFamily("Calibri"); } {{endregion}}

Figure 1: Setting different FontSize and FontFamily

{{ site.framework_name }} Setting different FontSize and FontFamily

The approach used in the above code snippets is applicable for the following themes - [Windows8]({%slug common-styles-appearance-colorizing-metro-theme%}#changing-fonts), [Windows8Touch]({%slug common-styles-appearance-colorizing-metro-theme%}#changing-fonts), [Office2013]({%slug common-styling-appearance-office2013-theme%}#changing-fonts), [VisualStudio2013]({%slug common-styling-appearance-visualstudio2013-theme%}#changing-fonts), [Office2016]({%slug common-styling-appearance-office2016-theme%}#changing-fonts), [Office2016Touch]({%slug common-styling-appearance-office2016touch-theme%}#changing-fonts), [Green]({%slug common-styling-appearance-green-theme%}#changing-fonts), [Fluent]({%slug common-styling-appearance-fluent-theme%}#changing-fonts), [Material]({%slug common-styling-appearance-material-theme%}#changing-fonts), [Crystal]({%slug common-styling-appearance-crystal-theme%}#changing-fonts) and [VisualStudio2019]({%slug common-styling-appearance-visualstudio2019-theme%}#changing-fonts).

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]({%slug common-styling-appearance-available-themes%})
  • [Theme Helper]({%slug styling-appearance-theme-helper%})
  • [Switching Themes at Runtime]({%slug styling-apperance-themes-runtime%})