问题
Hi I am trying to create a reusable XAML Window in a DLL.
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>
I get an exception that this styles don't exist, they are both declared in that ResourceDictionary which is in the Themes folder.
回答1:
From this post:
... as long as Project B has a reference to Project A.
<ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Project A;component/YourSubFolder/YourResourceFile.xaml" /> </ResourceDictionary.MergedDictionaries>
Then you can just use the Resources defined in YourResourceFile.xaml.
来源:https://stackoverflow.com/questions/1219141/how-to-style-a-xaml-window-with-a-resourcedictionary-that-exist-in-a-dll