多个解决方案之间共享的app.xaml [英] Shared app.xaml between multiple solutions

查看:92
本文介绍了多个解决方案之间共享的app.xaml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将要使用WPF创建多个项目.我正在使用样式来修改应用程序的外观并将它们放在app.xaml中.

I'm about to create multiple projects with WPF. I'm using styles to modify the look and feel of the applications and put them to the app.xaml.

但是现在我有一个问题,我需要在每个项目中使用相同的样式.因为将app.xaml内容复制并粘贴到每个项目是一个非常糟糕的主意,所以我正在寻找一种解决方案,以集中app.xaml来访问每个项目中的样式.

But now i have the problem that i need to have the same styles in every project. Because copy and paste of the app.xaml content to every project is a very bad idea I'm looking for a solution to centralize the app.xaml to access the styles from every project.

推荐答案

您可以在一个项目中创建一个通用样式文件.例如,这可能是一个包含您的样式和资源的 GenericStyles.xml 文件.

You might create a common styles file in one of your project. For example, this might be a GenericStyles.xml file containing your styles and resources.

在其他项目中,您可以作为链接添加此文件:右键单击项目->添加->现有项...->选择 GenericStyles.xml 文件->打开添加按钮上的下拉菜单->选择添加为链接.

In other projects, you could add this file as link: right click on a project -> Add -> Existing Item... -> select GenericStyles.xml file -> open the drop-down menu on the Add button -> select Add As Link.

因此,现在您只有一个文件,它将成为所有项目的一部分.

So now you have a single file that will be part of all your projects.

在每个项目的 app.xaml 中,您可以使用以下标记添加样式和资源:

In each project's app.xaml, you could add your styles and resources using this markup:

<ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="GenericStyles.xml"/>
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

现在,您只需要更改主"项目中的一个文件,其他项目将自动应用这些更改.

Now, you would have to change only one file in the "main" project, and the other projects would automatically apply these changes.

这篇关于多个解决方案之间共享的app.xaml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆