0

I am working with a Xaml file that is a custom view derived from a ViewBase, and I would like to access a DynamicResource that is in a different assembly. I have seen that it is possible to use something like:

<Application.Resources>
    <ResourceDictionary
    Source="/mylib;Resources/MyStyleDictionary.xaml" />
</Application.Resources>

However I'm dealing with a xaml file that looks something like:

<myLib:ViewBase> 
    <Grid>
        <Button>
            Style="{DynamicResource MyButtonStyle}" // I want this style to come from a different assembly
        </Button>
    </Grid>
 </myLib:ViewBase>

How can I do this?

Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
L. Desjardins
  • 1,465
  • 1
  • 12
  • 22

1 Answers1

1

It's important to understand the difference between Dynamic and Static resources. What's the difference between StaticResource and DynamicResource in WPF?

But to answer the question:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/SomeOtherAssembly;Resources/SomeOtherDictionaryWithMyButtonStyleKey.xaml" />
            <ResourceDictionary Source="/mylib;Resources/MyStyleDictionary.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

The resource is being referenced dynamically, so merging SomeOtherDictionaryWithMyButtonStyleKey.xaml before merging in MyStyleDictionary.xaml should work.

Community
  • 1
  • 1
user1834059
  • 502
  • 6
  • 16