MahApps.Metro按钮fontsize不是从metrowindow继承的

时间:2016-05-03 16:11:39

标签: c# wpf mahapps.metro

我开始学习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>

1 个答案:

答案 0 :(得分:0)

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>