devexpress设置系统全局字体(含工具栏字体)

本文介绍了如何使用DevExpress设置系统字体,并演示了数据绑定的实现方式。通过实例展示了如何将数据集与网格控件关联,以及BarManager组件如何自动应用全局字体设置,无需额外代码。提供了一个详细的代码示例及项目源码链接,方便开发者实践。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、许多时候,都需要设置系统的字体。devexpress设置字体效果图比较如下:

 上图比较可以看出,字体应用到了所有控件。

2、数据绑定代码:

            DataTable dt = new DataTable();
            dt.Columns.Add("A");
            dt.Columns.Add("B");
            dt.Columns.Add("C");
            dt.Columns.Add("D");
            for (int i = 0; i < 20; i++)
                dt.Rows.Add("数据列0000" + (i + 1), "测试列0000" + 2 * (i + 1), "列0000" + 3 * (i + 1), "数列0000" + 4 * (i + 1));
            gridControl1.DataSource = dt;

3、barmanage应用字体需要设置其应用字体的属性为true,再设置全局字体时。barmanage也将自动应用字体,无需增加额外代码。

4、项目案例源码链接(无需积分):http://download.youkuaiyun.com/detail/kehaigang29/8875691

5、交流群 298515749

转载于:https://www.cnblogs.com/ManchesterUnitedFootballClub/p/4626394.html

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- ============ 颜色基准 ============ --> <!-- ★ 新增说明详情:暗夜模式颜色与亮色保持语义一致,只调色值 --> <Color x:Key="WindowBgColor">#FF1E1E1E</Color> <Color x:Key="AltBgColor">#FF262626</Color> <Color x:Key="CardBorderColor">#FF383838</Color> <Color x:Key="AccentColor">#FF64B5F6</Color> <Color x:Key="AccentHoverColor">#FF8ABCF7</Color> <Color x:Key="TextFgColor">#FFF2F2F2</Color> <Color x:Key="SubTextFgColor">#FFB0B0B0</Color> <Color x:Key="DisabledFgColor">#FF707070</Color> <Color x:Key="DisabledBgColor">#FF3A3A3A</Color> <Color x:Key="HoverBgColor">#332196F3</Color> <!-- 半透明 Hover --> <Color x:Key="SelectedBgColor">#552196F3</Color> <!-- 半透明选中 --> <Color x:Key="SelectedFgColor">#FFFFFFFF</Color> <Color x:Key="ScrollBarThumbColor">#FF5E5E5E</Color> <!-- ============ 刷子封装 ============ --> <SolidColorBrush x:Key="WindowBgBrush" Color="{StaticResource WindowBgColor}" /> <SolidColorBrush x:Key="AltBgBrush" Color="{StaticResource AltBgColor}" /> <SolidColorBrush x:Key="CardBorderBrush"Color="{StaticResource CardBorderColor}" /> <SolidColorBrush x:Key="AccentBrush" Color="{StaticResource AccentColor}" /> <SolidColorBrush x:Key="AccentHoverBrush" Color="{StaticResource AccentHoverColor}" /> <SolidColorBrush x:Key="TextFgBrush" Color="{StaticResource TextFgColor}" /> <SolidColorBrush x:Key="SubTextFgBrush" Color="{StaticResource SubTextFgColor}" /> <SolidColorBrush x:Key="DisabledFgBrush"Color="{StaticResource DisabledFgColor}" /> <SolidColorBrush x:Key="DisabledBgBrush"Color="{StaticResource DisabledBgColor}" /> <SolidColorBrush x:Key="HoverBgBrush" Color="{StaticResource HoverBgColor}" /> <SolidColorBrush x:Key="SelectedBgBrush"Color="{StaticResource SelectedBgColor}" /> <SolidColorBrush x:Key="SelectedFgBrush"Color="{StaticResource SelectedFgColor}" /> <SolidColorBrush x:Key="ScrollBarThumbBrush" Color="{StaticResource ScrollBarThumbColor}" /> <!-- ============ 全局字体大小保持一致 ============ --> <sys:Double x:Key="FontSizeBase" xmlns:sys="clr-namespace:System;assembly=mscorlib">13</sys:Double> <!-- ============ Window ========= --> <Style TargetType="Window"> <Setter Property="Background" Value="{DynamicResource WindowBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="FontSize" Value="{DynamicResource FontSizeBase}"/> </Style> <!-- ============ Panel / Border / DockPanel / Grid 默认背景 ============ --> <Style TargetType="{x:Type Panel}"> <Setter Property="Background" Value="{DynamicResource WindowBgBrush}"/> </Style> <Style TargetType="Border"> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource CardBorderBrush}"/> <Setter Property="BorderThickness" Value="1"/> </Style> <!-- ============ TextBlock ============ --> <Style TargetType="TextBlock"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> </Style> <!-- ============ Button ============ --> <Style TargetType="Button"> <Setter Property="Background" Value="{DynamicResource AccentBrush}"/> <Setter Property="Foreground" Value="White"/> <Setter Property="BorderBrush" Value="{DynamicResource AccentBrush}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Padding" Value="6,2"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="{DynamicResource AccentHoverBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource AccentHoverBrush}"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" Value="{DynamicResource AccentHoverBrush}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" Value="{DynamicResource DisabledBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource DisabledFgBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource DisabledBgBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- ============ ToggleButton / CheckBox / RadioButton 统一色调 ============ --> <Style TargetType="ToggleButton" BasedOn="{StaticResource {x:Type Button}}"/> <Style TargetType="CheckBox"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> </Style> <Style TargetType="RadioButton" BasedOn="{StaticResource {x:Type CheckBox}}"/> <!-- ============ TextBox / ComboBox / Slider ============ --> <Style TargetType="TextBox"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource CardBorderBrush}"/> </Style> <Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type TextBox}}"/> <Style TargetType="Slider"> <Setter Property="Foreground" Value="{DynamicResource AccentBrush}"/> </Style> <!-- ============ ProgressBar ============ --> <Style TargetType="ProgressBar"> <Setter Property="Foreground" Value="{DynamicResource AccentBrush}"/> </Style> <!-- ============ ListBox / TreeView 行高亮 ============ --> <Style TargetType="ListBoxItem"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border x:Name="Bd" Background="{TemplateBinding Background}"> <ContentPresenter/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Bd" Property="Background" Value="{DynamicResource HoverBgBrush}"/> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectedBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource SelectedFgBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="TreeViewItem"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="Background" Value="Transparent"/> </Style> <!-- ============ ScrollBar ============ --> <Style TargetType="ScrollBar"> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="Width" Value="12"/> </Style> <Style TargetType="Thumb"> <Setter Property="Background" Value="{DynamicResource ScrollBarThumbBrush}"/> </Style> <!-- ============ ContextMenu / MenuItem ============ --> <Style TargetType="ContextMenu"> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> </Style> <Style TargetType="MenuItem"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Style.Triggers> <Trigger Property="IsHighlighted" Value="True"> <Setter Property="Background" Value="{DynamicResource HoverBgBrush}"/> </Trigger> </Style.Triggers> </Style> </ResourceDictionary><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- ============ 颜色基准 ============ --> <!-- ★ 新增说明详情:基础颜色,便于后续统一调整 --> <Color x:Key="WindowBgColor">#FFF7F7F7</Color> <!-- 整体背景 --> <Color x:Key="AltBgColor">#FFFFFFFF</Color> <!-- 卡片 / ToolBar 等 --> <Color x:Key="CardBorderColor">#FFE0E0E0</Color> <!-- 卡片边框 --> <Color x:Key="AccentColor">#FF2196F3</Color> <!-- 主高亮色 --> <Color x:Key="AccentHoverColor">#FF42A5F5</Color> <!-- 鼠标悬停高亮 --> <Color x:Key="TextFgColor">#FF212121</Color> <!-- 正文字体 --> <Color x:Key="SubTextFgColor">#FF555555</Color> <!-- 辅助说明文字 --> <Color x:Key="DisabledFgColor">#FF9E9E9E</Color> <!-- 失效文字 --> <Color x:Key="DisabledBgColor">#FFE0E0E0</Color> <!-- 失效背景 --> <Color x:Key="HoverBgColor">#FFE8F1FF</Color> <!-- Hover 行背景 --> <Color x:Key="SelectedBgColor">#FFCCE5FF</Color> <!-- 选中行背景 --> <Color x:Key="SelectedFgColor">#FF000000</Color> <!-- 选中文本 --> <Color x:Key="ScrollBarThumbColor">#FFC0C0C0</Color> <!-- 滚动条滑块 --> <!-- ============ 刷子封装 ============ --> <!-- ★ 新增说明详情:全部用 SolidColorBrush 并标记 Freeze --> <SolidColorBrush x:Key="WindowBgBrush" Color="{StaticResource WindowBgColor}" /> <SolidColorBrush x:Key="AltBgBrush" Color="{StaticResource AltBgColor}" /> <SolidColorBrush x:Key="CardBorderBrush"Color="{StaticResource CardBorderColor}" /> <SolidColorBrush x:Key="AccentBrush" Color="{StaticResource AccentColor}" /> <SolidColorBrush x:Key="AccentHoverBrush" Color="{StaticResource AccentHoverColor}" /> <SolidColorBrush x:Key="TextFgBrush" Color="{StaticResource TextFgColor}" /> <SolidColorBrush x:Key="SubTextFgBrush" Color="{StaticResource SubTextFgColor}" /> <SolidColorBrush x:Key="DisabledFgBrush"Color="{StaticResource DisabledFgColor}" /> <SolidColorBrush x:Key="DisabledBgBrush"Color="{StaticResource DisabledBgColor}" /> <SolidColorBrush x:Key="HoverBgBrush" Color="{StaticResource HoverBgColor}" /> <SolidColorBrush x:Key="SelectedBgBrush"Color="{StaticResource SelectedBgColor}" /> <SolidColorBrush x:Key="SelectedFgBrush"Color="{StaticResource SelectedFgColor}" /> <SolidColorBrush x:Key="ScrollBarThumbBrush" Color="{StaticResource ScrollBarThumbColor}" /> <!-- ============ 全局字体大小 ============ --> <sys:Double x:Key="FontSizeBase" xmlns:sys="clr-namespace:System;assembly=mscorlib">13</sys:Double> <!-- ============ Window ========= --> <!-- ★ 新增说明详情:所有窗口默认背景/前景 --> <Style TargetType="Window"> <Setter Property="Background" Value="{DynamicResource WindowBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="FontSize" Value="{DynamicResource FontSizeBase}"/> </Style> <!-- ============ Panel / Border / DockPanel / Grid 默认背景 ============ --> <Style TargetType="{x:Type Panel}"> <Setter Property="Background" Value="{DynamicResource WindowBgBrush}"/> </Style> <Style TargetType="Border"> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource CardBorderBrush}"/> <Setter Property="BorderThickness" Value="1"/> </Style> <!-- ============ TextBlock ============ --> <Style TargetType="TextBlock"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> </Style> <!-- ============ Button ============ --> <Style TargetType="Button"> <Setter Property="Background" Value="{DynamicResource AccentBrush}"/> <Setter Property="Foreground" Value="White"/> <Setter Property="BorderBrush" Value="{DynamicResource AccentBrush}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="Padding" Value="6,2"/> <Setter Property="Cursor" Value="Hand"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Background" Value="{DynamicResource AccentHoverBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource AccentHoverBrush}"/> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Background" Value="{DynamicResource AccentHoverBrush}"/> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Background" Value="{DynamicResource DisabledBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource DisabledFgBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource DisabledBgBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- ============ ToggleButton / CheckBox / RadioButton 统一色调 ============ --> <Style TargetType="ToggleButton" BasedOn="{StaticResource {x:Type Button}}"/> <Style TargetType="CheckBox"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> </Style> <Style TargetType="RadioButton" BasedOn="{StaticResource {x:Type CheckBox}}"/> <!-- ============ TextBox / ComboBox / Slider ============ --> <Style TargetType="TextBox"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="BorderBrush" Value="{DynamicResource CardBorderBrush}"/> </Style> <Style TargetType="ComboBox" BasedOn="{StaticResource {x:Type TextBox}}"/> <Style TargetType="Slider"> <Setter Property="Foreground" Value="{DynamicResource AccentBrush}"/> </Style> <!-- ============ ProgressBar ============ --> <Style TargetType="ProgressBar"> <Setter Property="Foreground" Value="{DynamicResource AccentBrush}"/> </Style> <!-- ============ ListBox / TreeView 行高亮 ============ --> <Style TargetType="ListBoxItem"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBoxItem"> <Border x:Name="Bd" Background="{TemplateBinding Background}"> <ContentPresenter/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter TargetName="Bd" Property="Background" Value="{DynamicResource HoverBgBrush}"/> </Trigger> <Trigger Property="IsSelected" Value="True"> <Setter TargetName="Bd" Property="Background" Value="{DynamicResource SelectedBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource SelectedFgBrush}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> <!-- TreeViewItem 同理 --> <Style TargetType="TreeViewItem"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Setter Property="Background" Value="Transparent"/> </Style> <!-- ============ ScrollBar ============ --> <Style TargetType="ScrollBar"> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="Width" Value="12"/> </Style> <Style TargetType="Thumb"> <Setter Property="Background" Value="{DynamicResource ScrollBarThumbBrush}"/> </Style> <!-- ============ ContextMenu / MenuItem ============ --> <Style TargetType="ContextMenu"> <Setter Property="Background" Value="{DynamicResource AltBgBrush}"/> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> </Style> <Style TargetType="MenuItem"> <Setter Property="Foreground" Value="{DynamicResource TextFgBrush}"/> <Style.Triggers> <Trigger Property="IsHighlighted" Value="True"> <Setter Property="Background" Value="{DynamicResource HoverBgBrush}"/> </Trigger> </Style.Triggers> </Style> </ResourceDictionary>严重性 代码 说明 项目 文件 行 抑制状态 详细信息 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\DarkTheme.xaml 26 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\DarkTheme.xaml 31 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\DarkTheme.xaml 32 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\DarkTheme.xaml 34 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\DarkTheme.xaml 35 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\LightTheme.xaml 38 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\LightTheme.xaml 43 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\LightTheme.xaml 44 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\LightTheme.xaml 46 错误 XLS0307 “Color”是导致 XML 无效的意外标记。应为空白。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\LightTheme.xaml 47 错误(活动) MC3000 ““Color”是一个意外标记。应为空格。 第 26 行,位置 45。.”XML 无效。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\DarkTheme.xaml 26 错误(活动) MC3000 ““Color”是一个意外标记。应为空格。 第 38 行,位置 45。.”XML 无效。 AssetStudio G:\我的程序开发\MyApp\AssetStudio\AssetStudio\Themes\LightTheme.xaml 38
最新发布
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值