【发布时间】:2018-08-10 08:17:23
【问题描述】:
我已经为我们的应用程序团队制作了几个ResourceDictionaries,以用于他们未来的应用程序。我已将包含这些字典的类库项目的内容部署到 .dll 文件中,并且希望能够通过在新的 WPF 解决方案中添加对 .dll 文件的引用来使用字典,我希望在其中创建一个新的应用程序.
在我的示例中,类库名为“NWF_Class_Library.dll”,并与 MainWindow.xaml 文件保存在 Windows 资源管理器中的同一文件夹中。是否可以从其中检索资源字典?
我已经阅读了有关组织使用arrange their xaml 资源的最佳方式的文章,所以它似乎必须是可能的,但我发现的只是使用“//pack:application:...”语法的方法在与 wpf 应用程序相同的解决方案中引用 xaml。这是一段 sn-p 代码,Source 为空白,因为我写的任何东西都没有用!
我们曾希望我们可以将标准配置以及我们更正常的有用方法等添加到可以与应用程序一起部署的文件中。
<Window x:Class="dll_ref_included.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<ResourceDictionary Source=""/>
</Window.Resources>
<Grid>
<Button Style="{StaticResource myButton}">This</Button>
</Grid>
</Window>
【问题讨论】:
-
可以使用 "//pack:application:..." 语法。您可以提供您希望使用的强程序集名称和资源名称。据我所知,这个程序集必须加载到您当前的 AppDomain 中(添加到您的项目的引用中,或手动添加)。
标签: c# wpf xaml dll resourcedictionary