【问题标题】:StaticResource where resource is in external assembly?StaticResource 资源在外部程序集中的位置?
【发布时间】:2011-10-07 15:40:14
【问题描述】:

基本上,我想将所有 XAML 资源保存在外部程序集中(用于我的样式)。我的应用程序中有这个外部程序集的引用。

是否与附属程序集或诸如此类的东西有关,或者我如何访问这些样式,以便我的应用程序仍然可以有 StaticResource 标记而不会出现编译错误?

【问题讨论】:

    标签: c# wpf xaml satellite-assembly staticresource


    【解决方案1】:

    假设您将样式保存在另一个程序集中的 ResourceDictionary 中,您只需将其与您当前的资源合并(无论它们是在 Window 还是 UserControl 或其他任何地方)。

    如果我们假设

    • 您的其他程序集名为“external.assembly.name”
    • ResourceDictionary 在命名空间 Resources 下;和
    • 字典名为“MyStyles.xaml”

    ...然后你可以合并字典如下:

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary 
                  Source="pack://application:,,,/external.assembly.name;component/Resources/MyStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <!-- other resources go here -->
        </ResourceDictionary>
    </UserControl.Resources>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多