views:

139

answers:

2

HI Can any one suggest me how bind viewmodel to a usercontrol..

Also please share different way of doing that..

I have added viewmodel and view into my xaml file in namespace and in the user control resource tag.. i have defined a data template with data type as the viewmodel wh i have wrote.. inside that i have added my view (i mean the same usercontrol ih which im editing now is it possible -- please let me know).. I have used content control with content={Binding}.. and contenttemplate as a datatemplate.. in that i have reffered the property which i want to bind from viewmodel).. but its not binding as such..

My query is different ways of binding viewmodel to view in UserControlLibrary Project ?

+1  A: 

Set the datacontext of your view, with an instance of your viewmodel. Throughout your view you can then bind to the properties of your viewmodel with "Path" in the binding.

Sdry
could you give me some example... For me the property which i am calling is not getting called... i put break points inside code.. and also i tried with all type of binding .. example(datacontext } then using dataTemplate.. Please help
Senthilkumar
post your code please
Sdry
+1  A: 

Sdry's right, you can also set the DataContext property of your view to your ViewModel.

Also, here's a WPF databinding cheat sheet that will likely come in handy: http://www.nbdtech.com/Free/WpfBinding.pdf

Dave