合并来自不同项目的 XAML 资源和样式时遇到问题

发布于 2024-11-03 12:06:33 字数 464 浏览 0 评论 0原文

我正在创建许多 WPF 应用程序,这些应用程序都与一个中央 WPF 应用程序相关,并且需要共享相同的样式和资源。首先,我在主项目中创建了一个文件夹,并添加了一些 XAML 样式,这些样式都可以以我想要的样式显示 UI。 后来,我创建了另一个应用程序,但想要共享相同的样式,因此我将样式移动到第三个项目中,将该项目添加到主应用程序中,并将引用添加到样式项目中。 问题是它将无法识别我的样式项目。我用项目名称作为样式前缀,但这根本不起作用。

现在,我可以在 ResourceDictionary 的“路径”部分中输入 xaml 文件的完整相对路径,并且可以正常工作。但是,如果我将项目移动到另一个文件夹,那么就会失败。我想你可能会问我为什么要这样做,这是有原因的,比如简单地重构我的项目结构。因此,通过引用而不是文件来寻址资源会更容易。

我知道答案就在咫尺之遥,但我找不到与另一个项目的样式相关的任何内容。

到目前为止,我从这个网站得到了很好的反馈,任何帮助将不胜感激。

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 enter 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海 2024-11-10 12:06:33

好吧,我已经怀疑了!基本上,您将样式添加到单独项目中的一组资源字典中,然后将该项目添加到解决方案中并在主项目中引用它。我已经做到了这一点,但需要从我的主项目中的资源中引用 xaml 资源文件。

我尝试使用完整路径名,但虽然有效,但这不是一个很好的解决方案,因为如果我移动我的项目并重新链接它,该文件将无效。

我使用的语法如下:

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

其中 StyleResources 是保存共享样式的项目的名称,MSResources 是保存 xaml 文件的样式项目中的文件夹,末尾的文件名很明显。
我还没有阅读有关“组件”的参考资料,但它确实有效,所以我稍后会查看它并更新这篇文章。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文