Hi Guido, yes, what you say is correct. However, I believe there have been a couple things lost in translation, so as a quick reminder, here is what i'm trying to accomplish:
In the following layout (much code omitted for brevity sake), UC1 is being added to a region via
All imports are satisfied properly on UC1. However, none of the imports are satisfied on UC2-UC5. UC2-UC5 are all different user controls that I want displayed at design time, therefore I am statically laying them out as opposed to relying
on Region Management to add them.
To satisfy their imports, I am relying on a call to ServiceLocator.Current.GetInstance<T>()
(4 times, for UC2-UC5) within the Loaded Event of UC1.
Doing this satisfies the imports, however, by the time that happens, the controls that depend on VM's in UC2-UC5 look to the DataContext in UC1. This is due to the imports being resolved too late.
Following your advice as a test, I have placed a call ServiceLocator.Current.GetInstance<T>()
within UC2's default public constructor (before call to InitializeComponent()), and this seems to have performed the trick (the controls that rely on databinding in UC2's XAML can find what they're looking for on the VM that is properly set as UC2's
But this approach will force me to have calls to ServiceLocator.Current.GetInstance<T>()
scattered throughout my code (in Views and ViewModels).
Surely there must be a better way to accomplish what I'm after? Perhaps I should just allow UC2-UC5 to be dynamically to the StackPanel in UC1 via a Region? Only problem with this, of course, as that I can't see UC2-UC5 displayed in UC1 at design
Please stick with me here, I think we're almost there. :)