无法访问 Silverlight 类库中的字体资源
我正在处理一个相当大的 Silveright 3.0 项目,并且在从其中一个程序集中访问几个自定义字体资源时遇到问题。
我有一个工作测试解决方案,其中我添加了自定义字体作为资源,并且可以使用以下方法从 XAML 很好地访问它:
<TextBlock Text="Test" FontFamily="FontName.ttf#Font Name" />
测试解决方案由 TestProject.Application 和 TestProject 组成.Application.Web 项目,所有乐趣和游戏显然都在 TestProject.Application 项目中
但是,当我在主解决方案中尝试此操作时,字体拒绝以正确的字体显示(而是以默认字体显示)字体)。测试解决方案和主解决方案之间将字体添加到项目的方式没有区别,并且 XAML 是相同的。
然而,解决方案布局存在差异。在主解决方案中,除了有 MainApp.Application 和 MainApp.Application.Web 项目外,我还有一个 MainApp.Application.ViewModel > 项目和一个 MainApp.Application.Views 项目,XAML 的问题部分位于 MainApp.Application.Views 项目中(而不是像测试解决方案那样的 .Application 项目)。
我尝试将字体放入 .Application 或 .Application.Views 项目中,尝试将构建操作更改为内容、嵌入式资源等,但均无济于事。
那么,从我不知道的子程序集中访问字体资源是否存在问题,或者有人成功地做到了这一点?
我的长期需求是将有效的自定义字体作为资源存储在单独的 .Application.FontLibrary 程序集中,该程序集将按需下载和缓存,并且 .Application.Views 项目中的 XAML 控件将需要引用此FontLibrary 程序集获取有效字体。我还尝试创建这个单独的字体库程序集,但我似乎无法从第二个程序集获取字体。
作为一些附加信息,我还尝试了以下字体引用方法:
<TextBlock Text="Test" FontFamily="/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;component/FontName.ttf#Font Name" />
以及一些具有不同程序集引用/子目录/随机分号的类似变体。
到目前为止,没有任何效果......有人遇到过这个问题(并且最好解决它)?
I have a reasonably large Silveright 3.0 project on the go, and I'm having issues accessing a couple of custom font resources from within one of the assemblies.
I've got a working test solution where I have added a custom font as a resource, and can access it fine from XAML using:
<TextBlock Text="Test" FontFamily="FontName.ttf#Font Name" />
The test solution consists of the TestProject.Application and the TestProject.Application.Web projects, with all the fun and games obviously in the TestProject.Application project
However, when I try this in my main solution, the fonts refuse to show in the correct type face (instead showing in the default font). There's no difference in the way the font has been added to project between the test solution and the main solution, and the XAML is identical.
However, there is a solution layout difference. In the main solution, as well as having a MainApp.Application and MainApp.Application.Web project, I also have a MainApp.Application.ViewModel project and a MainApp.Application.Views project, and the problem piece of XAML is the in the MainApp.Application.Views project (not the .Application project like the test solution).
I've tried putting the font into either the .Application or .Application.Views project, tried changing the Build Action to Content, Embedded Resource etc, all to no avail.
So, is there an issue accessing font resources from a child assembly that I don't know about, or has anyone successfully done this?
My long term need will be to have the valid custom fonts being stored as resources in a separate .Application.FontLibrary assembly that will be on-demand downloaded and cached, and the XAML controls in the .Application.Views project will need to reference this FontLibrary assembly to get the valid fonts. I've also tried xcreating this separate font library assembly, and I can't seem to get the fonts from the second assembly.
As some additional information, I've also tried the following font referencing approaches:
<TextBlock Text="Test" FontFamily="/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;/FontName.ttf#Font Name" />
<TextBlock Text="Test" FontFamily="pack:application,,,/MainApp.Application.Views;component/FontName.ttf#Font Name" />
And a few similar variants with different assembly references/sub directories/random semi colons.
And so far nothing works... anyone struck this (and preferably solved it)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码对我有用:
This code works for me: