如何使用DLL中存在的ResourceDictionary来创建XAML窗口? [英] How to style a XAML window with a ResourceDictionary that exist in a DLL?
问题描述
我试图在一个DLL中创建一个可重用的XAML窗口。
Hi I am trying to create a reusable XAML Window in a DLL.
我已经在Themes文件夹中放置了一个新的ResourceDictionary(甚至在Generic .xaml),但是当我尝试在窗口中使用它的样式时,我会收到一条错误消息,该样式不存在:
I have placed in the Themes folder a new ResourceDictionary (I even merged it in the Generic.xaml), but when I try to use its styles in the window, I get an error message that the style doesn't exist:
<Window Style="{StaticResource ModalWindowStyle}" >
<!-- I have also the following -->
<Window.Resources>
<Style TargetType="Button" BasedOn="{StaticResource ButtonStyle}" />
</Window.Resources>
</Window>
我收到一个例外,这种样式不存在,它们都在该ResourceDictionary中声明在Themes文件夹中。
I get an exception that this styles don't exist, they are both declared in that ResourceDictionary which is in the Themes folder.
推荐答案
从:
From this post:
$ b $只要项目B有一个项目A的引用,b...。
... as long as Project B has a reference to Project A.
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Project A;component/YourSubFolder/YourResourceFile.xaml" />
</ResourceDictionary.MergedDictionaries>
然后,您可以使用YourResourceFile.xaml中定义的资源。
Then you can just use the Resources defined in YourResourceFile.xaml.
这篇关于如何使用DLL中存在的ResourceDictionary来创建XAML窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!