Question

I have a basic MVVM light Windows Phone 8 app created. I have MainView, being shown as the startup page. This is automatically getting the datacontext of a new instance of MainViewModel.

I want to navigate to another view, and have a new viewmodel (or an existing one provided on navigation) set as the datacontext for that view.

How do I do this?

I have navigation working through http://mvvmlightnavigation.codeplex.com/SourceControl/latest#MVVMlightNavigationService/NavigationService.cs

Should I be using something else for navigation?

Was it helpful?

Solution

In the basePage tag in XAML

you can add your view model like this

<basepage:BaseApplicationPage 
DataContext="{Binding YourViewModel, Source={StaticResource Locator}}">

Make sure the you have to registered the ViewModel with the same name that you are giving in the data context. I am using MVVMlight, so ViewModel and View are registered in the 'ViewModelLocator'.

Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top