Reputation: 330
I am having a dll which contains a usercontrol and also the viewmodel for the control. I am using this usercontrol in another application. Now i don't know how to set the datacontext to the viewmodel in the dll.
This is the View Code of my application(The Window LayoutControlViewModel is the dll ViewModel):
<Window x:Class="TestApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dll="clr-namespace:WindowLayoutControl.View;assembly=WindowLayoutControl"
Title="MainWindow" Height="350" Width="525">
<Grid>
<dll:WindowLayoutControl DataContext="{Binding WindowLayoutControlViewModel}"></dll:WindowLayoutControl>
</Grid>
Sorry i am pretty new to mvvm and wpf. Thank you in advance.
Upvotes: 2
Views: 929
Reputation: 1325
You said that you have both View and ViewModel in that dll, so i'll asume that the ViewModel is in a separate namespace:
<Window x:Class="TestApplication.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dll="clr-namespace:WindowLayoutControl.View;assembly=WindowLayoutControl"
xmlns:dllViewModel="clr-namespace:WindowLayoutControl.ViewModel;assembly=WindowLayoutControl"
Title="MainWindow" Height="350" Width="525">
<Grid>
<dll:WindowLayoutControl>
<dll:WindowLayoutControl.DataContext>
<dllViewModel:{Name of your view model here}/>
</dll:WindowLayoutControl.DataContext>
</dll:WindowLayoutControl>
</Grid>
Upvotes: 2