mahapps:fontfamily没有使用定义的nell' app.xaml样式加载字体

时间:2016-02-03 13:42:12

标签: c# wpf xaml mahapps.metro

我的app.xaml

<Application x:Class="MyProject.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>            
            <Style x:Key="Lato-Regular">
                <Setter Property="TextElement.FontFamily" Value="pack://application:,,,/Resources/Font/#Lato-Regular" />
            </Style>

            <Style x:Key="Lato-Thin">
                <Setter Property="TextElement.FontFamily" Value="pack://application:,,,/Resources/Font/#Lato-Thin" />
            </Style>

            <Style x:Key="Lato-Semibold">
                <Setter Property="TextElement.FontFamily" Value="pack://application:,,,/Resources/Font/#Lato-Semibold" />
            </Style>            
            <ResourceDictionary.MergedDictionaries>                
                <ResourceDictionary Source="Themes/Generic.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>             
    </Application.Resources>
</Application>

我在解决方案中的字体&#34;资源/字体/:Lato-Regular.ttf,Lato-Thin.ttf,Lato-Semibold.ttf

我在textblock上的mainwindows.xaml:

<controls:MetroWindow x:Class="MainWindow.xaml"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:metro="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
      xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
      xmlns:p="clr-namespace:MyProject.Properties"
      xmlns:res="clr-namespace:MyProject.Properties;assembly=CDA"
      mc:Ignorable="d" d:DesignHeight="660" d:DesignWidth="800" Background="#DEDFE4"
      Title="HomePage">

    <Grid>
            <TextBlock  Style="{DynamicResource Lato-Regular}" MouseDown="HomePage_MouseDown" Text="HOMEPAGE" Grid.Row="3" HorizontalAlignment="Left" Margin="50,22,0,0" Foreground="#fff" FontSize="17" Height="Auto"></TextBlock>
    </Grid>
</<controls:MetroWindow>

我的字体是由&#34;的属性设置的。总是复制&#34; ,他们在解决方案。 我不明白为什么不应该去,软件部分但字体仍然是WPF视图构建的标准。 它可以是Mahapps包括它的字体,并且排除了那些强加给我的人吗?

1 个答案:

答案 0 :(得分:0)

是的,MahApps定义了自己的字体,并在许多控件中使用。 在MahApps的源树\ Style \ Fonts.xaml中,定义了以下内容:

<FontFamily x:Key="DefaultFont">Segoe UI, Lucida Sans Unicode, Verdana</FontFamily>
<FontFamily x:Key="HeaderFontFamily">Segoe UI Light, Lucida Sans Unicode, Verdana</FontFamily>
<FontFamily x:Key="ContentFontFamily">Segoe UI, Lucida Sans Unicode, Verdana</FontFamily>
<FontFamily x:Key="ToggleSwitchFontFamily">Segoe UI Semibold, Segoe UI, Lucida Sans Unicode, Verdana</FontFamily>
<FontFamily x:Key="ToggleSwitchHeaderFontFamily">Segoe UI Semibold, Segoe UI, Lucida Sans Unicode, Verdana</FontFamily>

此外,搜索整个MahApps的Segou UI项目,并且应该有其他一些项目可能会受到影响。

就个人而言,我发现使用我的字体制作MahApp的最简单方法就是修改其源代码并构建我自己的源代码。