对按需加载的程序集中资源的 Uri 引用
我确实按需加载一个程序集,其中包含资源(字体)。 该程序集正在由 AssemblyPart 类加载, 因此添加到当前应用程序域。
txt1.FontFamily = New FontFamily("/SilverlightFontLibrary;component/GRAFFITO_01.ttf#Graffito")
Dim kaa = Application.GetResourceStream("/SilverlightFontLibrary;component/GRAFFITO_01.ttf".ToUri(UriKind.Relative))
字体没有应用于文本,但我确实获得了资源流。
如果程序集位于 xap 包内,则一切正常, 但将其设置为复制本地 false 它不会显示正确的字体。 :(
我无法使用 FontSource
将字体直接设置为流(我肯定有), 因为像 Run
、Paragraph
或 RichTextBox
这样的类根本没有它们。 ;(
有谁知道 MEF (Microsoft Extensibility Framework) 是否可以帮助我解决这个问题?
有什么已知的方法可以实现这一点吗?
我真的需要引用这些资源,但无法将它们全部放入一个 xap 包中。
:(问候
I do load an assembly on demand which holds ressources (fonts) in it.
The assembly is being loaded by the AssemblyPart class,
and therefore added to the current application domain.
txt1.FontFamily = New FontFamily("/SilverlightFontLibrary;component/GRAFFITO_01.ttf#Graffito")
Dim kaa = Application.GetResourceStream("/SilverlightFontLibrary;component/GRAFFITO_01.ttf".ToUri(UriKind.Relative))
The font is not being applied to the text, but I do get the ressource stream.
If the assembly is inside the xap package everything works fine,
but setting it to copy local false it won't show the correct font. :(
I cannot use the FontSource
to set the font directly as stream (which I definately have),
because classes like Run
, Paragraph
or the RichTextBox
simply do not have them. ;(
Does anybody know whether MEF (Microsoft Extensibility Framework) can help me out of this?
Is there any known way to accomplish that?
I seriously need to refer to those ressources, but cannot put them all into one xap package. :(
Kind regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑解除主项目对了解字体完整 URL 的依赖。相反,在您的其他项目引用的第三个项目中创建一个
IFontProvider
接口(对 C# 表示歉意,我不使用 VB.NET):-在您的字体库中创建此接口的实现:-
使用加载到域中的库程序集您应该能够访问字体:-
通过从同一组件内的代码使用“组件”url,它应该能够找到资源。
有一些关于 MEF 和动态程序集加载的博客,因此您可以使用它动态地将
IFontProvider
类型的字段与库实现连接起来。Consider de-coupling your main project's dependency on knowing the full url to the font. Instead create an
IFontProvider
interface in a third project referenced by both your other projects (apologies for C# I don't do VB.NET) :-In your font library create an implementation of this:-
With the library assembly loaded into the domain you should be able to access a font:-
With the "component" url being used from code within the same component it should be able to find the resource.
There are some blogs on MEF and Dynamic assembly loading so you may be able to use it dynamically wire up a field of type
IFontProvider
with the library implementation.