KB Article S35762
Visible to All Users

How to change font settings for all XAF UI elements (toolbar and context menus, property editors, etc.)

WinForms

In an XAF application, you can integrate standard solutions recommended for DevExpress WinForms controls depending on one of the two use-case scenarios:

Option 1 (Static)

1.1. Globally. If you want to adjust this only once and everywhere, set the static DefaultFont and DefaultMenuFont properties of the DevExpress.XtraEditors.WindowsFormsSettings class in SolutionName.Win/Program.xx file or any other place before the actual form is shown.

C#
namespace SolutionName.Win { public class Program { [STAThread] public static void Main(string[] arguments) { DevExpress.XtraEditors.WindowsFormsSettings.DefaultFont = new System.Drawing.Font("Tahoma", 14); DevExpress.XtraEditors.WindowsFormsSettings.DefaultMenuFont = new System.Drawing.Font("Tahoma", 12);

Alternatively, you can use the WinForms Project Settings Page (.NET Framework only at present, font settings are stored in the SolutionName.Win/app.config file):
Clipboard-File-2.png

1.2. Locally. If you want to adjust this in certain places only, use the How to: Apply HTML Formatting to Windows Forms XAF UI Elements.

Option 2 (Dynamic)

If you need to update font styles at runtime when the form is already created and shown, you cannot use the DevExpress.XtraEditors.WindowsFormsSettings.DefaultMenuFont property. That is because the BarAndDockingController settings are cached and not reset by default (this may be changed in the future versions of our WinForms Suite). So, for now, consider the following approach: close the form, customize the BarAndDockingController class properties as detailed in the Appearance and Look and Feel > Bar and Docking Controller documentation article, and then reopen your form.
As for the XAF integration, refer to the following WindowController:

C#
using System; using System.Drawing; using DevExpress.Utils; using DevExpress.XtraBars; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Win.Controls; namespace YourSolutionName.Module.Win { public class S35762 : WindowController { static S35762() { AppearanceObject.DefaultFont = new Font("Segoe UI", 10); } protected override void OnActivated() { base.OnActivated(); Window.TemplateChanged += Window_TemplateChanged; } private void Window_TemplateChanged(object sender, EventArgs e) { if(Frame.Template is IBarManagerHolder) { BarManager manager = ((IBarManagerHolder)Frame.Template).BarManager; if(manager.Controller == null) { manager.Controller = new BarAndDockingController(); } var controller = manager.Controller; controller.AppearancesBar.MainMenu.Font = AppearanceObject.DefaultFont; controller.AppearancesBar.ItemsFont = AppearanceObject.DefaultFont; } } protected override void OnDeactivated() { Window.TemplateChanged -= Window_TemplateChanged; base.OnDeactivated(); } } }
Visual Basic
Option Infer On Imports System Imports System.Drawing Imports DevExpress.Utils Imports DevExpress.XtraBars Imports DevExpress.ExpressApp Imports DevExpress.ExpressApp.Win.Controls Namespace YourSolutionName.Module.Win Public Class S35762 Inherits WindowController Shared Sub New() AppearanceObject.DefaultFont = New Font("Segoe UI", 10) End Sub Protected Overrides Sub OnActivated() MyBase.OnActivated() AddHandler Window.TemplateChanged, AddressOf Window_TemplateChanged End Sub Private Sub Window_TemplateChanged(ByVal sender As Object, ByVal e As EventArgs) If TypeOf Frame.Template Is IBarManagerHolder Then Dim manager As BarManager = DirectCast(Frame.Template, IBarManagerHolder).BarManager If manager.Controller Is Nothing Then manager.Controller = New BarAndDockingController() End If Dim controller = manager.Controller controller.AppearancesBar.MainMenu.Font = AppearanceObject.DefaultFont controller.AppearancesBar.ItemsFont = AppearanceObject.DefaultFont End If End Sub Protected Overrides Sub OnDeactivated() RemoveHandler Window.TemplateChanged, AddressOf Window_TemplateChanged MyBase.OnDeactivated() End Sub End Class End Namespace

Note: this code is designed for the new XAF WinForms templates (WinApplication.UseOldTemplates = False).

ASP.NET WebForms

You can change these settings either via CSS or via code, programmatically. Refer to the How can i change default font in web application ticket for more details and specific examples.

ASP.NET Core Blazor

As XAF Blazor uses Bootstrap rendering, an application gets fonts from the current theme. To change the default font, add the following style to the YourSolutionName.Blazor.Server\Pages_Host.cshtml file:

HTML
@page "/" @namespace dxT1190331.Blazor.Server @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @using DevExpress.ExpressApp.Blazor.Components <!DOCTYPE html> <html lang="en"> <head> @*...*@ <style> body{ font-family: Comic Sans MS; } </style> </head>

Common

Depending on your business requirements, you can change these font settings dynamically via custom Actions or attributes in the Model Editor tool. Refer to the How to: Extend the Application Model and Add an Action with Option Selection help topics to learn more on how to enhance these solutions further. A good reference implementation that joins these two concepts together in one sample project can be found in the How to globally change font size of all UI controls (editors, toolbar and context menus, etc.)  ticket (WinForms only).

Comments (1)
Apostolis Bekiaris (DevExpress) 11 years ago

    Our community project users can change the font from eXpandFramework v13.2.5.5 as described in http://www.expandframework.com/forum/6-bugs/3781-in-imodelrepositoryitem-not-show-complex-properties-for-example-font.html#5598

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.