How to style a XAML window with a ResourceDictionary that exist in a DLL?

ぐ巨炮叔叔 提交于 2019-12-11 00:58:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!