WP7 SL - How can I use two different View Models in a View. One VM: Display, other for User input and acting on it
I am using ViewModelLocator pattern. I have the following situation:
Page1<->VM1 => Navigate => Page2<->VM1 => Navigate => Page3<->VM3
=> Page 4<->VM4 => Page 5<->VM5
I will show Page2 using VM1 but the controls that will take input will bind to another VM2. This way I can take care of display usin开发者_开发知识库g content from VM1 and take action for user input using VM2. How can I achieve this in a clean way. Is there a better alternative approach for such scenario?
thanks.
If you need to bind to 2 different VMs in a single view just bind the second ViewModel to the "root" element of the section you want to bind to that VM. In other words set the datacontext via DataContext="{Binding Source={StaticResource viewModelLocator}, Path=ViewModel}"
精彩评论