应用程序的默认FontFamily [英] Default FontFamily for application
问题描述
我想创建一种样式,该样式将为整个应用程序设置字体家族,并允许我在一处更改字体系列,并使新字体在整个应用程序中显示.我创建了以下样式,但我的控件(如标签)仍默认为segoe.如何创建将所有控件设置为相同字体系列的样式,除非我用本地样式覆盖该样式.
I want to create at style that will set the fontfamily for my entire application and allow me to change the font family in one place and have the new font show up throughout my application. I created the following style but my controls like my labels still default to segoe. How can I create a style that will set my all my controls to the same font family except where I override the style with a local style.
< Style TargetType ="{x:Type Control}">
< Setter Property ="FontFamily"值="Constantia"/>
</Style>
<Style TargetType="{x:Type Control}">
<Setter Property="FontFamily" Value="Constantia"/>
</Style>
推荐答案
Hi, what you can do is to define a "global" style for the Control class, like what you have already done, then have other control-specific styles to be derived or BasedOn that, then apply that style to the actual control. For example:
< StackPanel xmlns =" http://schemas.microsoft.com/winfx/2006/xaml >
< StackPanel.Resources>
< Style TargetType ="{x:Type Control}" x:Key ="ControlStyle">
< Setter Property ="FontFamily"值="Constantia"/>
</Style>
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel.Resources>
<Style TargetType="{x:Type Control}" x:Key="ControlStyle">
<Setter Property="FontFamily" Value="Constantia"/>
</Style>
< Style TargetType ="{x:Type Label}" x:Key ="LabelStyle"; BasedOn =< {StaticResource ControlStyle}" >
< Setter Property =" FontWeight"值=粗体"; />
</Style>
< Style TargetType =< {x:Type Button}" x:Key ="ButtonStyle"; BasedOn =< {StaticResource ControlStyle}">
< Setter Property =< Background"值=蓝色"/>
</Style>
</StackPanel.Resources>
Style =" {{StaticResource LabelStyle}"> Label</Label>
< Button Style =" {StaticResource ButtonStyle}< >这是一个Button</Button>
</StackPanel>
<Label Style="{StaticResource LabelStyle}">This is a Label</Label>
<Button Style="{StaticResource ButtonStyle}">This is a Button</Button>
</StackPanel>
这样,Label和Button都将具有Constantia字体,但也具有自己的样式. (标签为粗体,按钮为蓝色背景)
This way, both the Label and Button will have Constantia font but also have their own styles. (Bold for Label, and Blue background for Button)
希望这会有所帮助.
谢谢.
这篇关于应用程序的默认FontFamily的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!