【问题标题】:How to create a solution wide ResouceDictionary如何创建解决方案范围的 ResouceDictionary
【发布时间】:2018-06-04 07:59:31
【问题描述】:

我正在使用 Prism 模块。这意味着我的解决方案中有很多项目,我想在所有项目中分享我的 WPF 样式。

目前我只是将它们添加到我所有的 xaml 文件中。 例如:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Pack://application:,,,/MyProject.Shared;component/Styles/Colors.xaml" />
        </ResourceDictionary.MergedDictionaries>
    <ResourceDictionary>
<UserControl.Resources>

我想知道这个问题是否有更好的解决方案。

编辑:“可能重复”实际上是我目前正在做的事情。 我想在我的每个用户控件中摆脱这个重复的代码 sn-p。因为我的大多数项目都是UserControlLibraries / Prism Modules,所以他们没有App.xaml 可以在其中定义资源字典。

【问题讨论】:

标签: c# wpf xaml prism


【解决方案1】:

默认 WPF 项目应该有一个 App.xaml 文件。假设你的项目仍然有这个,你可以在Application.Resources标签下添加你的资源字典。

见:https://docs.microsoft.com/en-us/dotnet/framework/wpf/app-development/how-to-use-an-application-scope-resource-dictionary

【讨论】:

    猜你喜欢
    • 2011-02-06
    • 2011-07-06
    • 2011-01-18
    • 2011-03-10
    • 1970-01-01
    • 2023-03-12
    • 2012-08-28
    • 1970-01-01
    • 2017-12-30
    相关资源
    最近更新 更多