1
votes

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 ?

2
some code might clarify things up. - Samuel DR

2 Answers

2
votes

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

1
votes

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.