简体   繁体   English

StaticResource资源在外部程序集中的位置?

[英]StaticResource where resource is in external assembly?

Basically, I want to keep all my XAML resources in an external assembly (for my styles). 基本上,我想将所有XAML资源保存在外部程序集中(对于我的样式)。 I have a reference of this external assembly in my application. 我在我的应用程序中引用了这个外部程序集。

Is there something to do with satellite assemblies or whatnot or how do I go about accessing these styles so that my application can still have StaticResource tags without compilation errors? 有没有关于附属程序集或诸如此类的内容或如何访问这些样式,以便我的应用程序仍然可以具有StaticResource标记而没有编译错误?

Assuming you keep your styles in a ResourceDictionary in the other assembly, you just need to merge it with your current resources (whether they are on a Window or UserControl or whatever). 假设您将样式保存在另一个程序集中的ResourceDictionary中,您只需将其与当前资源合并(无论它们是在Window还是UserControl上等)。

If we assume that 如果我们假设

  • your other assembly is named 'external.assembly.name' 你的另一个程序集名为'external.assembly.name'
  • the ResourceDictionary is under the namespace Resources; ResourceDictionary位于命名空间Resources下; and
  • the dictionary is named 'MyStyles.xaml' 字典名为'MyStyles.xaml'

...then you can merge the dictionaries as below: ...然后你可以合并下面的字典:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么ListBox ItemTemplateSelector =“ {StaticResource MyDataTemplateSelector}”不能与资源一起使用? - Why is the ListBox ItemTemplateSelector=“{StaticResource MyDataTemplateSelector}” not working with the resource? 如何将外部程序集作为资源集成到.net可执行文件中 - How can I integrate an external assembly as a resource into a .net executable 从另一个程序集加载时,StaticResource导致XamlParseException - StaticResource causes XamlParseException when loaded from another assembly 如何以及在何处为Simple XAML窗口中的转换器创建StaticResource密钥? - How and Where to Create StaticResource Key for a Converter within the Simple XAML Window? 来自程序集的资源作为流 - Resource from assembly as a stream 预加载资源组装? - Preload resource assembly? 访问外部装配反射 - Accessing external Assembly Reflection 引用/外部程序集中的MapMvcAttributeRoutes - MapMvcAttributeRoutes in Referenced/External Assembly 汇编...内部和外部命名空间 - Assembly … internal & external namespacing 为什么我必须将自定义ValueConverter声明为StaticResource并绑定到资源,而不是绑定到它的类型? - Why do I have to declare a custom ValueConverter as a StaticResource and bind to the resource, instead of binding to its type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM