0

I have a solution which loads a WPF App that Holds multiple resource dictionaries as merged ones. One of them contains converters, some certain collection, templates. Others contain templates and other stuff. Some of the dictionaries are loaded from other compiled DLLs.

My problem is that certain dictionaries require to use resources from other dictionaries. Although I could reference them, I would like to avoid that. I would like to have them to access each other in a centralized way.

Is there a way to do this already, that I am missing, or can someone point me to a article conceerning this?. I was googleing but found nothing

EDIT

This solution worked fine, until the moment I tried using a converter as a DynamicResource in a binding. Any sugestions?

<Image Margin="0" Width="20" DockPanel.Dock="Left" StretchDirection="Both"
                       Source="{Binding MessageCode, Converter={DynamicResource MessageImageConverter}, ConverterParameter=True, FallbackValue='0'}"
                       />

this is the code

user853710
  • 1,715
  • 1
  • 13
  • 27

2 Answers2

1

Use "{DynamicResource myresource}" instead of "{StaticResource myresource}".

If your assembly A.exe has the required dictionaries in its wpf tree, then sub-controls of referenced assembly B.dll will find required resource.

You will not see the expected result in WPF designer, though.

Olivier
  • 5,578
  • 2
  • 31
  • 46
  • would the dictionary from A.exe need to have a XAML reference to the dictionaries from B.DLL? Or is it possible that both of them would take care of it on its own as merged dictionaries simply by using DynamicResource instead of StaticResource? – user853710 Feb 12 '14 at 15:52
  • 1
    resource dictionaries have no need to "know" each other with DynamicResource. They can be in totally separated assemblies, and A.exe can even not have any reference chain to B.dll (which means that you're using reflection to instantiate controls from B.dll) – Olivier Feb 12 '14 at 17:40
  • Correct. Converter is not a DependencyProperty. It is set only once at Binding instanciation... which means that if the resource is not resolved at instanciation time, it wont be set at all. – Olivier Feb 13 '14 at 09:27
  • OK. how can I go around it – user853710 Feb 13 '14 at 09:31
  • 1
    Stop using resources for converters :) a trick is to make your IValueConverter a child class of MarkupExtension. See http://stackoverflow.com/questions/7445119/improved-ivalueconverter-markupextension-or-dependencyobject – Olivier Feb 13 '14 at 09:41
0

Perhaps using a dependency injection framework. WPF utilizes Unity/Prism as it's default framework of choice. You could leverage that same concept in your dll's

xspydr
  • 3,030
  • 3
  • 31
  • 49