I have the following case on my WPF app :
I have a main user control with its MainViewModel which binded to the control datacontext .
Inside the main control , I have an item control which item source is binded to List .
the item control has a user control as its template which draw the users details , each template as we know has User as its Datacontext .
My question :
How I can use the Main control datacontext (MainViewModel) in the template user control . I tried to use mef to import MainViewModel but the problem its exported with creation policy “NonShared” so the import will bring new instances of the MainViewModel and not the one of the Main control .
Thanks in advance …
If you are trying to use MEF, you could always compose the existing value with a unique name, e.g.:
That way, you can always provide an import for it in your user control:
Where
ComposeExportedValueis an extension method belonging to theAttributedModelServicestype.