简体   繁体   English

MahApps.Metro按钮的字体大小不是从Metrowindow继承的

[英]MahApps.Metro button fontsize is not inherited from metrowindow

I am beginning to learn WPF and I choose MahApps.Metro for styling as it looked cool. 我开始学习WPF,并且选择MahApps.Metro进行样式设计,因为它看起来很酷。 The problem I am facing is that after changing the font of MetroWindow the WindowCommandButton's font is updated accordingly but the font of the buttons is not getting updated. 我面临的问题是,更改MetroWindow的字体后,WindowCommandButton的字体会相应更新,但按钮的字体不会更新。 I continue to see tiny texted buttons. 我继续看到细小的文本按钮。

My XAML looks like this as of now 到目前为止,我的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 doesn't inherit from parent control. Button.FontFamily不继承自父控件。 It is defined in the base style : 它以基本样式定义:

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

You can override that with the following : 您可以使用以下命令覆盖它:

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

Or, you can override that globally for every style that also happens to use it via (but, don't do this) : 或者,您也可以针对也恰巧通过它使用它的每种样式全局覆盖(但不要这样做):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM