我在我的新Windows 10通用应用程序C#/ XAML上遇到以下错误:
GalaSoft.MvvmLight.Platform.dll中出现类型'System.InvalidCastException'的例外,但未在用户代码中处理.附加信息:无法将类型''的对象强制转换为'Windows.UI.Xaml.Controls.Frame'.
在我的一个页面视图模型中的以下导航命令中:
_navigationService.NavigateTo(ViewModelLocator.MedicineBoxPageKey);
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用汉堡包菜单样式导航(请参阅此示例).应用程序由Microsoft提供如何执行此操作的示例):
1-在我的所有页面中共享一个方便的解决方案.上面提到的示例使用AppShell Page作为应用程序的根而不是Frame,它封装了导航菜单和后退按钮的某些行为.那将是理想的.
2-使用MVVM-Light导航服务可以方便地处理视图模型中的所有导航.
以下是App.xml.Cs如何初始化shell页面onLaunched:
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 a a 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) …Run Code Online (Sandbox Code Playgroud)