开发者

Trouble merging XAML resources and styles from different project

开发者 https://www.devze.com 2023-02-28 13:45 出处:网络
I am creating a number of WPF applications that all relate around one central WPF application and need to share the same styles and resources. In the first place I created a folder in my main project

I am creating a number of WPF applications that all relate around one central WPF application and need to share the same styles and resources. In the first place I created a folder in my main project and added some XAML styles which all worked in displaying UI in the styles I wanted. Later, I created another application but wanted to share the same styles so I moved the styles into a third project, added that project to the main application and added the reference to the styles project. The problem is that the will not recognise my styles project. I prefixed the style with the project name and that did not work at all.

I have now got to the point where I can e开发者_如何转开发nter the entire relative path to the xaml files in the Path section of the ResourceDictionary and that works. However, If I move the project to another folder then that would fail. I suppose you may ask why I would do that and there are reasons, such as simply refactoring my project structure. Therefore, it would be easier to address the resources by reference rather than file.

I know the answer is inches away but I cannot find anything related to styles from another project.

I have had great feedback from this site so far and any help would be greatly appreciated.


OK, I have sussed it! Basically, you add your styles to a set of resource dictionaries in a separate project then you add the project to the solution and make a reference to it in your main project. I got that far but needed to reference the xaml resource files from my resources in my main project.

I tried using the full path name but while that worked, it was not a very good solution because if I move my project and re-link it, the file will because invalid.

The syntax I used that works is as follows:

<ResourceDictionary Source="/StyleResource;component/MSResources/TabControl.xaml" />

Where StyleResources is the name of my project that holds my shared styles, MSResources is the folder in the styles project that holds the xaml file and the file name at the end is obvious. I have not yet read up about the “component” reference but it works so I will look at it later and update this post.

0

精彩评论

暂无评论...
验证码 换一张
取 消