MahApps.Metro 按钮字体大小没有继承自metrowindow

MahApps.Metro button fontsize is not inherited from metrowindow

我开始学习 WPF,我选择 MahApps.Metro 作为样式,因为它看起来很酷。我面临的问题是,在更改 MetroWindow 的字体后,WindowCommandButton 的字体会相应更新,但按钮的字体不会更新。我继续看到微小的文字按钮。

我的 XAML 目前看起来是这样的

<MahApps:MetroWindow
    x:Class="MetroSample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:MetroSample"

    xmlns:MahApps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"

    mc:Ignorable="d"
    Title="Metro Sample" 
    Height="350" Width="525"
    WindowStartupLocation="CenterScreen"
    GlowBrush="{DynamicResource AccentColorBrush}" FontFamily="Lucida Sans Unicode" FontSize="14.667">

<MahApps:MetroWindow.RightWindowCommands>
    <MahApps:WindowCommands>
        <Button x:Name="btnReqLogs">
            <StackPanel Orientation="Horizontal">
                <Rectangle Width="20" Height="20" Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
                    <Rectangle.OpacityMask>
                        <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_book_list}" />
                    </Rectangle.OpacityMask>
                </Rectangle>
                <TextBlock Margin="4 0 0 0" VerticalAlignment="Center" Text="Request Logs" />
            </StackPanel>
        </Button>

        <Button x:Name="btnSettings">
            <StackPanel Orientation="Horizontal">
                <Rectangle Width="20" Height="20" Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
                    <Rectangle.OpacityMask>
                        <VisualBrush Stretch="Fill" Visual="{StaticResource appbar_settings}" />
                    </Rectangle.OpacityMask>
                </Rectangle>
                <TextBlock Margin="4 0 0 0" VerticalAlignment="Center" Text="Settings" />
            </StackPanel>
        </Button>
    </MahApps:WindowCommands>
</MahApps:MetroWindow.RightWindowCommands>

<DockPanel LastChildFill="True">

    <DockPanel Height="50" DockPanel.Dock="Top" LastChildFill="False">
        <Button DockPanel.Dock="Left"
            MahApps:ButtonHelper.PreserveTextCase="True" Background="Transparent"
            Content="First Button" Padding="10,0" Width="150" Margin="0,0,2,0"/>

        <Button DockPanel.Dock="Left"
            MahApps:ButtonHelper.PreserveTextCase="True" Background="Transparent"
            Content="Second Button" Padding="10,0" Width="150" Margin="0,0,2,0"/>

        <Button DockPanel.Dock="Right"
            MahApps:ButtonHelper.PreserveTextCase="True" Background="Transparent"
            Content="Logout" Padding="10,0" Width="150" Margin="0,0,2,0"/>
    </DockPanel>

    <StackPanel>

    </StackPanel>
</DockPanel>

Button.FontFamily 不从父控件继承。 It is defined in the base style :

<Setter Property="FontFamily" Value="{DynamicResource DefaultFont}" />

您可以使用以下内容覆盖它:

<Style BasedOn="{StaticResource MetroButton}" TargetType="Button">
    <Setter Property="FontFamily" Value="Lucida Sans Unicode" />
</Style>

或者,您可以通过(但不要这样做)为每种恰好使用它的样式全局覆盖它:

<FontFamily x:Key="DefaultFont">Lucida Sans Unicode</FontFamily>