Lets say I have a WPF application that shows a ListBox with an ArrayList -populated with objects of arbitrary types- as a source, and this application is hosted in an assembly ‘A’. By default the ListBox will display the custom object ‘ToString’ method return value. If a data template for that object type is found, the ListBox will use it for rendering.
Imagine that theres another assembly ‘B’ that references of ‘A’ and seeks to extend it by providing custom data templates for certain types, to be used in that ListBox. Is there some way to do that without ‘A’being aware of B?
Lets say I have a WPF application that shows a ListBox with an ArrayList
Share
Yes, this is a very common usage of WPF.
In your assembly B:
<ResourceDictionary>tag<ResourceDictionary>tag, add DataTemplates and ControlTemplates for the types in BIn your AssemblyInfo.cs file, add the following line:
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
Now in your assembly A:
var assembly = Assembly.LoadFile(path)to load itActivator.CreateInstance(assembly.GetType(typeName))to create an object in assembly B knowing only its nameThe templates defined in assembly B will be used to present the controls and data in assembly B, even though assembly A knows nothing of assembly B.