I use the following error in my new 10 universal C # / XAML applications:
An exception of type "System.InvalidCastException" occurred in GalaSoft.MvvmLight.Platform.dll, but was not processed in the user code Additional information: It is not possible to overlay an object of type '' on type 'Windows.UI.Xaml.Controls.Frame'.
in the following navigation command in one of my pageview models:
_navigationService.NavigateTo(ViewModelLocator.MedicineBoxPageKey);
I am trying to use hamburger style navigation (see this example ). Microsoft application on the example of how to do this):
1- have a convenient solution for all my pages. The sample mentioned above uses the AppShell page as the application root instead of a frame that encapsulates the navigation menu and some back button behavior. That would be perfect.
2- Use the MVVM-Light navigation service to conveniently handle all navigation from my view model.
This is how App.xml.Cs initializes the onLaunched shell page:
AppShell shell = Window.Current.Content as AppShell; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (shell == null) { // Create aa AppShell to act as the navigation context and navigate to the first page shell = new AppShell(); // Set the default language shell.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; shell.AppFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } } // Place our app shell in the current Window Window.Current.Content = shell; if (shell.AppFrame.Content == null) { // When the navigation stack isn't restored, navigate to the first page // suppressing the initial entrance animation. shell.AppFrame.Navigate(typeof(MedicinesStorePage), e.Arguments, new Windows.UI.Xaml.Media.Animation.SuppressNavigationTransitionInfo()); } // Ensure the current window is active Window.Current.Activate();
And here is the definition of the AppShell class:
public sealed partial class AppShell : Page { public static AppShell Current = null; public AppShell() { this.InitializeComponent(); } }
From what I have tried so far, the mvvm-light navigation service only works when Frame uses the root of the application and marks the page (otherwise we will get this error). However, using a frame does not seem to be an option, because since the sample application puts it:
Using the page as the root for the application provides development time, and also ensures that when it runs on Mobile, the contents of the application will not be displayed under the StatusBar system, which is visible by default with a transparent background. It will also take into account the availability of software navigation buttons if they are displayed on the device. An application may refuse by switching to UseCoreWindow.
I also tried to override the navigationTo method from the mvvm-light navigation service, but the error seems to have occurred before I could catch it.
Does anyone have a solution to use the mvvm-light navigation service and the shell page as the root of the application (which controls the hamburger menu, etc.)?
Thanks a lot!