简体   繁体   English

Windows Phone 8中的自定义字体用法

[英]Custom font usage in Windows Phone 8

I have a weird problem with the Windows Phone 8 emulator! 我对Windows Phone 8模拟器有一个奇怪的问题! I have a small test app where I change the 'page name' textbox on the mainpage so that it shows using a custom font. 我有一个小测试应用程序,我在主页上更改“页面名称”文本框,以便使用自定义字体显示。 Now in the visual studio designer I see that font and when running the app I also see it in the emulator, so all is well... 现在在视觉工作室设计师中我看到了这种字体,在运行应用程序时我也在模拟器中看到它,所以一切都很好......

But when I move the main page into a folder called View and change the WMAppManifest.xml to reflect this move > Navigation page is now set to View/MainPage.xaml. 但是,当我将主页面移动到名为View的文件夹并更改WMAppManifest.xml以反映此移动时>导航页面现在设置为View / MainPage.xaml。 I'm still seeing this custom font in my designer, but not anymore in the emulator!! 我仍然在我的设计师中看到这种自定义字体,但在模拟器中不再!

I don't own a wp8 device yet... so can anyone verify this for me, if this problem is the same when you try to deploy the failure project to the phone? 我还没有拥有wp8设备......所以任何人都可以为我验证这一点,如果您尝试将故障项目部署到手机时这个问题是否相同?

And does anybody have any clue why this is happening? 有没有人知道为什么会这样? Very annoying not able to see the correct design in the emulator. 非常讨厌无法在模拟器中看到正确的设计。

Working and failing projects 工作和失败的项目

Ok found the solution myself... it's because of the reference to the font inside the styles.xaml. 好的,我自己找到了解决方案...这是因为找到了styles.xaml中的字体。

It should be a full path! 它应该是一条完整的道路! So instead of setting: 所以不要设置:

<Setter Property="FontFamily" Value="Fonts/ClementePDae-Light.ttf#ClementePDae" />

Set this: 设置此:

<Setter Property="FontFamily" Value="/PhoneApp1;component/Fonts/ClementePDae-Light.ttf#ClementePDae" />

Than everything works! 比一切都好!

I hope you found the solution already. 我希望你已经找到了解决方案。 Please check out How to add Custom Fonts 请查看如何添加自定义字体

This worked for me on Windows Phone 8 (Lumia 920) 这适用于Windows Phone 8(Lumia 920)
It is very important to hashtag the font name after the .ttf 在.ttf之后标记字体名称非常重要
You can find the font name if you preview the ttf file on your PC and write the exact same font name. 如果在PC上预览ttf文件并写入完全相同的字体名称,则可以找到字体名称。

First of all, you should save the external ttf into your project(If you want to use external font). 首先,您应该将外部ttf保存到项目中(如果要使用外部字体)。

Then, you can use this: 然后,你可以使用这个:

FontFamily="Helvetica.ttf#Helvetica"

FontFamily="Cookies.ttf#Cookies"    

When the .ttf font file is in the root folder, works fine in Design and Runtime. 当.ttf字体文件位于根文件夹中时,在Design和Runtime中工作正常。

FontFamily="/FontsTestApp;component/Cookies.ttf#Cookies"    

Same as above. 与上述相同。

FontFamily="/Font/Cookies.ttf#Cookies

When the .ttf font file is in the sub folder "font". 当.ttf字体文件位于子文件夹“font”中时。 Works fine in Design and Runtime. 在设计和运行时工作正常。

FontFamily="../Fonts/Cookies.ttf#Cookies";

When the XAML file which uses the font resides in another subfolder. 当使用该字体的XAML文件驻留在另一个子文件夹中时。 Works fine in Design and Runtime. 在设计和运行时工作正常。

FontFamily="../Fonts/Cookies.ttf#Cookies";  

If the XAML file is in the root folder, the font gets applied only at runtime not at design time. 如果XAML文件位于根文件夹中,则字体仅在运行时应用,而不是在设计时应用。

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

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