Reputation: 95
I have my View called "FahrgemeinschaftenView.xaml" & my ViewModel "Fahrgemeinschaften.cs." So by default the View is bound to its own cs, which in this case would be "FahrgemeinschaftenView.xaml.cs". Im very new to MVVM, but it says the ModelViewlayer should contain all the logic. So i try to connect "FahrgemeinschaftenView.xaml" with "FahrgemeinschaftenViewModel.cs", but wasn`t able to figure out how do to that (Passing Data).
Upvotes: 1
Views: 2228
Reputation: 36
Your view (in this case FahrgemeinschaftenView) has a property named DataContext. The simplest way of binding your view to your ViewModel is setting an instance of FahrgemeinschaftenViewModel to the DataContext property on your view.
You can do this in your constructor in FahrgemeinschaftenView.xaml.cs. Just write:
DataContext = new FahrgemeinschaftenViewModel();
right under the call to InitializeComponent()
public FahrgemeinschaftenView()
{
InitializeComponent();
DataContext = new FahrgemeinschaftenViewModel();
}
Upvotes: 1