[UWP] [C#]字体 [英] [UWP][C#]Fonts

查看:92
本文介绍了[UWP] [C#]字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在为我的UWP C#项目添加自定义字体时遇到了一些问题。我已将字体拖入Assets文件夹。然后我设置一个文本块的字体,如下所示:

I seem to be having a few issues adding custom fonts to my UWP C# project. I have dragged the font into the Assets folder. I am then setting the font of a text block like this:

myTextBlock.FontFamily = new FontFamily(" Assets / BerlingskeSansRound-Lt.otf#Berlingske Sans Round Lt);

myTextBlock.FontFamily = new FontFamily("Assets/BerlingskeSansRound-Lt.otf#Berlingske Sans Round Lt");

然而,这似乎有效 - 如果我将字体名称更改为任何内容,例如"ghfyghghg";显示的字体看起来一样。

However this does seem to be working - if I change the font name to anything for example "ghfyghghg" the displayed font looks the same.

我哪里错了? (在XAML编辑器中,添加的字体显示在文本块属性中,但选择它们似乎不会更改显示的字体)。

Where am I going wrong? (in the XAML editor the added fonts appear in the text block properties however selecting them doesn't seem to change the displayed font).

我在iOS和Android中使用这些完全相同的字体好的......

I am using these exact same fonts in iOS and Android OK...

同样在字体问题上我似乎无法设置fontweight:

Also while on the subject of fonts I cant seem to set fontweight:

myTextBlock.FontWeight =但是FontWeights属性枚举 似乎没有 - 我错过了什么?

myTextBlock.FontWeight = but the FontWeights property enum does not appear to be available - am I missing something?

谢谢!!!

推荐答案

你好,

>>然而这确实有效

>>However this does seem to be working

这里有拼写错误?

>> 如果我将字体名称更改为任何内容,例如"ghfyghghg"显示的字体看起来一样。

>> if I change the font name to anything for example "ghfyghghg" the displayed font looks the same.

你能确定BerlingskeSansRound-Lt.otf使用这个名字:"Berlingske Sans Round Lt"。我在本地机器上没有这种字体,所以我无法重现你的问题。但是,当我使用其他自定义字体系列时,它工作正常。

Can you be sure that BerlingskeSansRound-Lt.otf use this name: "Berlingske Sans Round Lt". I do not have this font in my local machine so I cannot reproduce your problem. But when I use other custom font family it works fine.

请注意,这应该是您的路径:  Assets / BerlingskeSansRound-Lt.otf 和"#"之后的单词是你的字体名称:"Berlingske Sans Round Lt"。有时它们可​​能会有所不同,比如这个帖子提到:

https://stackoverflow.com/questions/39155735/xamarin-forms-uwp-fonts/39171476#39171476

Please notice that this should be your path: Assets/BerlingskeSansRound-Lt.otf  and the words after "#" is your font name:"Berlingske Sans Round Lt". And some times they may different, like this thread mentioned: https://stackoverflow.com/questions/39155735/xamarin-forms-uwp-fonts/39171476#39171476.

顺便说一下,对于FontWeight,请注意FontWeights是一个类,您需要使用以下代码:

By the way, for the FontWeight, please notice that FontWeights is a class and you need to use the following code:

 mytextblock.FontWeight = Font​Weights.Light;

请记住,您需要添加以下命名空间:

Remember that you need to add the following namespace:

using Windows.UI.Text;

最好的问候,

Barry


这篇关于[UWP] [C#]字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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