Get Data from ViewModel in Code behind using MVVM
-
Hello to All, Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture. Thanks in Adv..
this.LayoutRoot.DataContext
This assumes the layoutroot has the data context assigned (otherwise just this.datacontext). You will also need to cast the datacontext back to your viewmodel
Never underestimate the power of human stupidity RAH
-
Hello to All, Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture. Thanks in Adv..
You should be setting the Datacontext of the page to the viewmodel somewhere if you are implementing MVVM correctly.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
-
Hello to All, Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture. Thanks in Adv..
One of the aspects of MVVM is that you don't have any code behind. The only thing thats "allowed" in the code behind is manipulating visuals. The fact that you want to interact with the ViewModel from the code behind is definitely wrong.