views:

582

answers:

1

Hi there,

I have been getting my feet wet with MVVM pattern for WPF and everything is working as it should..

But i am wiring up the viewmodel to my view datacontext from my codebehind of my window.

Sure enough the point of MVVM is to get rid of code behind in windows... which it does great, so i am left with 2 simple lines to wire up my datacontext to my viewmodel.

Is there an alternative?

Or is it acceptable to have only 2 lines to wire up the Viewmodel in my window code behind?

Is it possible to wire up the viewmodel to the view via XAML? I think it probably is (unsure) - But would this cause issues? Is it recommended?

Really appreciated any help?

+2  A: 

Yes, you can wire up the DataContext to the view through XAML via DataTemplates. You can see an example of this in the excellent and highly recommended article WPF Apps With The Model-View-ViewModel Design Pattern by Josh Smith.

Mark Seemann
thank you, good reading
mark smith