如何使用与Windows通用应用程序自定义字体? [英] How to use a custom font with Windows Universal app?

查看:581
本文介绍了如何使用与Windows通用应用程序自定义字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜欢我的其他的Windows Phone 8的项目,我想使用自定义字体。但随着新通用的应用程序架构我很难把那个到位。

Like for my other windows phone 8 projects I wanted to use a custom font. But with the new Universal app architecture I struggle to put that in place.

我已经在共享项目中创造了一个字体文件夹中,我添加的字体文​​件用属性生成操作内容。

I have created a "Fonts" folder in the shared project, I added the fonts files with the property Build Action to "Content".

我也创造了共享的项目一个主题文件夹,我添加了一个ResourceDictionnary它(Generic.xaml)。

I also created a "Themes" folder in the shared project and I added a ResourceDictionnary to it ("Generic.xaml").

我添加了一个的FontFamily资源:

I added a FontFamily resource :

<FontFamily x:Key="RexBoldFontFamily">/Fonts/Rex Bold.otf#Rex Bold</FontFamily>



我引用它在App.xaml中这样的:

I referenced it in the App.xaml like that:

<Application.Resources>

    <ResourceDictionary>

        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Themes/Generic.xaml"/>
        </ResourceDictionary.MergedDictionaries>

        <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="true" />

    </ResourceDictionary>

</Application.Resources>

在我在我的Windows Phone项目MainPage.xaml中我试图用这样的:

In my MainPage.xaml on my Windows Phone project I tried to use it like this:

<TextBlock Text="{Binding HelloWorld}" Foreground="{ThemeResource RedBrush}" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="{StaticResource RexBoldFontFamily}" FontSize="22"/>



我肯定知道这是字体的名字,因为这个工程在我的Windows手机之一应用程序。而这一切是很好的有线,因为它用一种颜色的资源效果很好。

I know for sure that this is the name of the font because this works on one of my windows phone app. And all of this is well wired because it works well with a color resource.

任何一个succeded共享字体和使用它,

Any one succeded to share the font and use it,

推荐答案

您在做这一切的权利,除了字体的名称(#后面的部分)。这似乎是雷克斯​​,不雷克斯粗体

You're doing it all right, except for the font name (part after the '#'). It seems to be Rex, not Rex Bold.

<FontFamily x:Key="RexBoldFontFamily">/Fonts/Rex Bold.otf#Rex</FontFamily>

这篇关于如何使用与Windows通用应用程序自定义字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆