WPF全局字体大小 [英] WPF global font size
问题描述
我正在创建一个WPF应用程序,我想知道能够更改UI中每个元素的字体大小的最佳方法。我创建一个资源字典,并设置样式来设置我使用的所有控件的字体大小?
最佳做法是什么?
我会这样做:
< ; Window.Resources>
< Style TargetType ={x:Type Control}x:Key =baseStyle>
< Setter Property =FontSizeValue =100/>
< / style>
< Style TargetType ={x:Type Button}BasedOn ={StaticResource baseStyle}>< / style>
< Style TargetType ={x:Type Label}BasedOn ={StaticResource baseStyle}>< / style>
< Style TargetType ={x:Type TextBox}BasedOn ={StaticResource baseStyle}>< / style>
< Style TargetType ={x:Type ListView}BasedOn ={StaticResource baseStyle}>< / style>
<! - ComboBox,RadioButton,CheckBox等... - >
< /Window.Resources>
这样,如果我想要更改所有的控件,我只需要将 baseStyle风格,其余的只是继承它。 (这就是那些BasedOn属性的那些,如果你在继承的样式中创建其他setter的话,你也可以扩展基础样式)。
I'm creating a WPF app and I would like to know the best way to be able to change the font size for every element in the ui. Do I create a resource dictionary and set Styles to set the font size for all the controls I use?
What is the best practice?
I'd do it this way:
<Window.Resources>
<Style TargetType="{x:Type Control}" x:Key="baseStyle">
<Setter Property="FontSize" Value="100" />
</Style>
<Style TargetType="{x:Type Button}" BasedOn="{StaticResource baseStyle}"></Style>
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource baseStyle}"></Style>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource baseStyle}"></Style>
<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource baseStyle}"></Style>
<!-- ComboBox, RadioButton, CheckBox, etc... -->
</Window.Resources>
That way, if I want to change ALL the controls, I'd just have to change the "baseStyle" style, the rest would just inherit from it. (That's what BasedOn property those, you can also extend the base style if you create other setters inside of the inherited style)
这篇关于WPF全局字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!