I have user control and its associated Viewmodel namely, ChildView and ChildViewModel. Code is as follows,
public partial class ChildView { public ChildView() { InitializeComponent(); } [Import] public ChildViewModel Model { get { return this.DataContext as ChildViewModel; } set { this.DataContext = value; } } }
Now, i want to use ChildView in MainWindow of another assembly. Sample code is as below,
<Window x:Class="Test.MainWindow" ... ><Grid><externalAssembly:ChildView/></Grid></Window>
this creates an instance of ChildView, it is fine. But it is not injecting ChildViewModel hence, getting Model property in view as NULL always.
How can I instantiate and inject ViewModels both to the child view and the MainWindow using MEF?