Can WPF ResourceDictionary return a new instance for each request

We use ResourceDictionaries to store layout information for our application. Lazy initialization is excellent, because we can capture the required layout for an element only when this element is created. The problem is that each element gets the same instance from the ResourceDictionary for each of them, which shares the layout (or the same if it goes out of scope and is needed later).

We could store the templates in a dictionary, then it doesn’t matter if they are shared, but we have a pretty good system if it weren’t for this caching behavior.

Is there a way to change this dictionary behavior or will I have to write my own class that creates elements from XAML on request?

+4
source share
1 answer

Try applying x: Shared = "false". Then each resource should receive a separate copy.

+4
source

All Articles