WPF: 应用资源相当于 DLL

我决定有两个项目。 第一个项目

这是

依恋 WPF, 其他普通人

项目 DLL. 在项目中 DLL 我有一些自定义控件 WPF. 我希望这些控件共同使用一些资源并确定它们 DLL.

我知道在通常的应用程序中 WPF 您可以指定应用程序资源 App.xaml. 项目中是否有相同的 DLL?
已邀请:

涵秋

赞同来自:

是的,您可以创建资源 XAML 在 DLL 通过以下方式 /确保您拥有所有构建 WPF, 提到了什么 DLL/:


 name of the dictionary is MyResources in MyDLL namespace 
<resourcedictionary x:class="MyDLL.MyResources" xmlns="[url=http://schemas.microsoft.com/winfx/2006/xaml/presentation"]http://schemas.microsoft.com/w ... ot%3B[/url] xmlns:x="[url=http://schemas.microsoft.com/winfx/2006/xaml">]http://schemas.microsoft.com/w ... gt%3B[/url]
<resourcedictionary.mergeddictionaries>
<resourcedictionary source="./Controls/ButtonStyles.xaml"></resourcedictionary>
</resourcedictionary.mergeddictionaries>
</resourcedictionary>


并将其添加到项目中的应用程序类的资源。 WPF:


public App//
{
MyDLL.MyResources externalRes = new MyDLL.MyResources//;

this.Resources.Add/"MyExternalResources", externalRes/;
}

三叔

赞同来自:

没有等同于 dll 不,因为资源加载不成部分 assembly /exe/, 以及部分申请。 要下载资源,您必须下载应用程序。 应用程序是应用程序的根元素,而不是 exe assembly. 使控件等同于 dll, 您可以创建一个单独的 ResourceDictionary 并将其添加到每个控件元素 XAML, 将它与资源相结合 UserControl 通过 ResourceDictionary.MergedDictionaries.

要回复问题请先登录注册