Visual Studio设计不显示嵌入式字体嵌入式、字体、Visual、Studio

2023-09-04 12:59:43 作者:夕阳,那般美つ

我使用一些自定义的字体在我的C#的WPF .NET 4.0应用程序(开放式SAN和FontAwesome,特别是)与Visual Studio 2013。

I'm using some custom fonts in my C# WPF .NET 4.0 application (Open Sans and FontAwesome, specifically) with Visual Studio 2013.

我有:

新增FontAwesome.otf和OpenSans-Regular.ttf到我的项目(​​而不是链接)下的/字体。 在确信两种字体都设置为资源。 在安装了字体本地(的Windows 8.1)。 在我的资源字典中创建新的样式(包含许多其他作品,所以我相信它的工作)。 重启动VS2013。

下面是我在我的资源字典创建的风格的一个片段:

Here is a snippet of the Style I've created in my Resource Dictionary:

<Style x:Key="OpenSans">
    <Setter Property="TextElement.FontFamily" Value="pack://application:,,,/Fonts/#Open Sans" />
</Style>

<Style x:Key="FontAwesome">
    <Setter Property="TextElement.FontFamily" Value="pack://application:,,,/Fonts/#FontAwesome" />
</Style>

现在,在一个新的用户控件我创建纯粹是为了测试设计和融入这些字体正确,我写了下面的XAML:

Now, in a new User Control I created purely to test the Designer and these fonts being included properly, I have written the following XAML:

    <TextBlock Style="{StaticResource FontAwesome}" FontSize="64" Text="&#xf085;" />
    <TextBlock Style="{StaticResource OpenSans}" FontSize="48" Text="the quick brown fox jumped over the lazy dog." />
    <TextBlock FontFamily="Open Sans" FontSize="48" Text="the quick brown fox jumped over the lazy dog." />

FontAwesome在设计师的作品和运行的时候,无论我的电脑和无FoneAwesome另一台PC上安装。

FontAwesome works in the designer and when run, on both my PC and another PC without FoneAwesome installed.

在OpenSans风格不会在设计师的显示,但在执行时不包括没有安装打开三世另一台PC上。

The OpenSans Style does not display in the designer, but does when executed, including on another PC without Open Sans installed.

在设计开放三世的FontFamily选择显示器,但不显示没有打开三世另一台电脑上安装(预期)。

The Open Sans FontFamily selection displays in the designer, but does not display on another PC without Open Sans installed (expected).

问题

我希望能够使用设计器看到设计时是什么UI的样子给我使用的是提供的字体。利用我所创建的风格,我能看到FontAwesome图标的设计,而不是开放Sans字体。唯一的区别我可以在两者之间讲的是FontAwesome是一个开放型的字体,而开放三世是一个真正的-Type字体。

I want to be able to use the Designer to see in design-time what the UI looks like given the provided Fonts I'm using. Leveraging the Styles I've created, I'm able to see the FontAwesome icons in the Designer, but not the Open Sans font. The only difference I can tell between the two is that FontAwesome is an Open-Type Font, whereas Open Sans is an True-Type Font.

没有任何人有一个想法,如果我忽略了一些简单的,或者是否有在VS设计OTF和TTF之间模糊的问题?

Does anyone have an idea if I've overlooked something simple, or perhaps if there are obscure issues between OTF and TTF in the VS Designer?

推荐答案

发现和放大器;解决方法

我不能辨别为什么打开三世未呈现,在VS设计。每一个尝试,我做了强迫它使用开放三世(从连接到该项目的字体资源)会失败,并且设计回落到默认的字体。

I cannot discern why Open Sans is not rendering in the VS Designer. Every attempt I've made to coerce it to use Open Sans (from the font resource attached to the project) will fail, and the Designer falls back to the default font.

使用作品如预期一样的方法FontAwesome,所以有一些元素的字体渲染系统中的VS,我无法解释。

Using the same methods with FontAwesome works as expected, so there is some element to the font rendering system within VS that I can't explain.

不过,我想出了一个好(甚至更好?)解决方案,以及一个提示,我不知道在WPF字体选择:

However, I have come up a good (perhaps even better?) solution, and a tip that I didn't know about font selection in WPF:

该的FontFamily属性在WPF支持回退值,例如:

The FontFamily Property in WPF supports fallback values, e.g.:

<Style x:Key="OpenSans">
    <Setter Property="TextElement.FontFamily" Value="Open Sans, /<project name>;component/Fonts/#Open Sans" />
</Style>

请注意,这家酒店的价值首先是打开三世,然后按照一个逗号,URI中,向被包含在项目的字体。 (在此提醒您,您需要确保字体资源的类型为资源下生成操作属性(在解决方案资源管理器中的字体文件,用鼠标右键单击。))

Notice that the Value of this Property is firstly "Open Sans", and then following a comma, the URI to the font that's included in the project. (As a reminder, you need to be sure the font resource is of type "Resource" under Build Action Properties (Right-click on the Font file within the Solution Explorer.))

本语法通知WPF使用列出的第一个字体,如果没有用,要那么回退到第二个字体系列,等等下来就行了。

This syntax informs WPF to use the first font listed, and if not available, to then fallback to the second font family, and so forth on down the line.

这是(可能)一个更好的解决方案,因为它要求该系统,如果需要的字体(在这个例子中,打开三世)已经可用。如果是这样,它使用该系统字体,如果没有,它会加载嵌入的字体文件资源

This is (potentially) a better solution, as it asks the system if the desired font (in this example, Open Sans) is already available. If so, it uses that system font, and if not, it will load the embedded font file resource.

这提供了几个好处:

该设置会导致VS设计来显示使用开放三世(在本例中),我使用他们的字体,这样我就可以设计并看到有问题的字体。

This setup causes the VS Designer to display fonts using Open Sans (in this example) where I use them, so I can design and see the font in question.

这个设置还允许与正在使用的字体机从系统中加载的第一个,如果没有找到,那么从资源加载。也许一个小的性能志同道合的项目,但还是有利的。

This setup also allows machines with the fonts being used to be loaded from the system first, and if not found, then load from the resource. Perhaps a minor performance-minded item, but still beneficial.

我希望这是对别人谁使用开放三世(或其他字体)有利,由于某种原因在VS设计器不会出现,除非引用直接作为系统字体。

I hope this is beneficial to others who use Open Sans (or other fonts) that for some reason will not show up in the VS Designer unless referenced directly as a system font.