在运行时动态合并资源字典(对于插件)

发布于 2024-08-04 10:43:01 字数 284 浏览 4 评论 0原文

我正在为 WPF 应用程序使用托管扩展性框架。我已经为所谓的扩展点定义了接口,这些扩展点为应用程序提供了新功能。

其中一些功能可能是使用某些数据模板显示数据,您可能希望在 xaml 资源文件中指定这些内容。

如果我在应用程序编译时未知的程序集中定义了这些扩展点之一(即简单语言的插件),但我仍然想将插件的资源与应用程序的资源合并,我将如何处理?

所有显示如何使用 pack URI 表示法执行此操作的示例都表明,当您引用的程序集在编译时已知时,这是解决方案。当您不熟悉编译时的程序集时,如何实现同样的目标?

I am using the Managed Extensibility Framework for a WPF application. I've defined interfaces for so-called extension points which provide new features to the application.

Some of these features might be to display data using certain data templates, which is something which you will probably want to specify in a xaml resources file.

If I have one of these extension points (ie plugins in plain language) defined in an assembly which is not known at application compile time, but I still want to merge the plugin's resources with those of the application how would I go about it?

All the examples that shows how to do this using the pack URI notation state that is the solution when the assemblies that you reference are known at compile time. How do you achieve the same thing when you aren't familiar with the assembly at compile-time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

李不 2024-08-11 10:43:01

您需要通过代码或约定获取要合并的资源字典的详细信息。详细信息可以是资源字典的名称或 ResourceDictionary 实例本身。

在后一种情况下,您拥有 ResourceDictionary 实例,因此您可以将其合并到 Application 级(或任何合适的级别)资源中。

在前一种情况下,您需要构建适当的 使用程序集名称打包 URI(您可以通过调用 extension.GetType().Assembly 从扩展中获取该名称)。然后创建一个 ResourceDictionary,其 Source 设置为 pack URI。最后,将其合并到资源树的适当级别中。

You need to get - either by code or convention - the details of the resource dictionary to be merged. The details could be the name of the resource dictionary or the ResourceDictionary instance itself.

In the latter case, you have the ResourceDictionary instance so you can just merge it into your Application-level (or whatever level is suitable) resources.

In the former case, you'll need to construct an appropriate pack URI using the name of the assembly (which you can get from the extension by calling extension.GetType().Assembly). Then create a ResourceDictionary whose Source is set to the pack URI. Finally, merge that into the appropriate level of your resource tree.

冰雪之触 2024-08-11 10:43:01

以下是如何将资源字典从部件提取到应用程序资源中: MEF(在本例中为数据模板)。我将 SoapBox Core 基于这种为视图导入资源字典的方法。

Here's how to pull in resource dictionaries from parts into your application resources using MEF (in this case for data templates). I based SoapBox Core on this method of importing resource dictionaries for Views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文