Nested Resource Dictionary in separate library

谁都会走 提交于 2019-12-03 08:56:55

I am currently unable to test this, however I hope it should work.

Rather than a rooted path, use a relative path in Project 2, i.e.

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Components/Type/CheckBox.xaml"/>
</ResourceDictionary.MergedDictionaries>

You may also use .. as required to navigate up to a relative directory (depending upon the location of CommonStyle.xaml), e.g.

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../Components/Type/CheckBox.xaml"/>
</ResourceDictionary.MergedDictionaries>

I believe when you use a rooted path (starting with /) it will look for CheckBox.xaml in the root of the project where you use CommonStyle.xaml rather than relative to the location of CommonStyle.xaml.

Additional Explanation

From you have described, it seems you have the following structure:

- Project 1
  - Window.xaml
- Project 2
  - CommonStyle.xaml
  - Components
    - Type
      - CheckBox.xaml

When CommonStyle.xaml refers to / it is normally referring to the root of Project 2, however when you merge this into Window.xaml the / would now refer to the root of Project 1, subsequently it is unable to locate Components/Type/CheckBox.xaml.

By removing the / it will now look for Components/Type/CheckBox.xaml relative to the location of CommonStyle.xaml which it is able to do.

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