【问题标题】:How to change all element's font family wpf-xaml如何更改所有元素的字体系列 wpf-xaml
【发布时间】:2017-12-16 16:05:46
【问题描述】:

我使用 MetroDark 主题。

我在 xaml 中使用此代码:

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Theme/MetroDark/MetroDark.MSControls.Core.Implicit.xaml" />
                <ResourceDictionary Source="Theme/MetroDark/MetroDark.MSControls.Toolkit.Implicit.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Style TargetType="{x:Type Label}" >
                <Setter Property="FontFamily" Value="B titr" />
                <Setter Property="FontSize" Value="13" />
                <Setter Property="FontWeight" Value="Bold" />
            </Style>
            <Style TargetType="{x:Type TextBox}" >
                <Setter Property="FontFamily" Value="B Nazanin" />
                <Setter Property="FontSize" Value="16" />
                <Setter Property="FontWeight" Value="Bold" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>

字体系列已正确更改,但背景颜色也已更改。

我只想更改字体系列和字体大小,以及另一个属性(例如:背景、边框等)并从默认主题(MetroDark)中获得效果。

我该怎么做?

【问题讨论】:

    标签: c# wpf xaml element font-family


    【解决方案1】:

    BasedOn 属性中设置基本样式,如下所示:

    <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
    
    <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
    

    这样自定义样式继承了基本样式的所有设置,并且可以覆盖其中的一些设置

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 1970-01-01
      • 2018-06-27
      • 1970-01-01
      • 2016-10-15
      • 2023-03-27
      相关资源
      最近更新 更多