MVVM Cross ShowViewModel 不适用于具有自定义的 UWP
MVVM Cross ShowViewModel doesn't work on UWP with custom
我参考了 this Whosebug 问题,关于 MVVM Light:
I am trying to have a hamburger menu style navigation (see this
sample). app by Microsoft on an example of how to do this) to:
1- have a convenient solution shared across all my pages. The sample
mentioned above uses an AppShell Page as the root of the app instead
of a Frame, that encapsulates the navigation menu and some behavior of
the back button. That would be ideal.
2- Use the MVVM-Light navigation service to handle all the navigation
from my view model conveniently.
下面是 App.xml.Cs 如何在启动时初始化 shell 页面:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
var 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 AppShell to act as the navigation context and navigate to the first page
shell = new AppShell();
// Set the default language
shell.Language = ApplicationLanguages.Languages[0];
shell.AppFrame.NavigationFailed += OnNavigationFailed;
}
// 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.
var setup = new Setup(shell.AppFrame);
setup.Initialize();
var start = Mvx.Resolve<IMvxAppStart>();
start.Start();
}
// Ensure the current window is active
Window.Current.Activate();
}
事实是,只要我浏览 AppShell 提供的菜单,一切正常。但是来自 MVVM Cross 的 ShowViewModel 没有任何效果。
我认为如果将 shell 作为框架或在 AppShell 上设置的框架传递,应该没有任何区别。
有没有人知道我能做些什么,或者是否有一个带有 MVVM cross 的工作汉堡菜单的例子?
如果您需要更好的概述,该存储库在 GitHub 上是开源的。
https://github.com/Apply-Solutions/MoneyManager
我使用 MVVM Cross v4.0.0.0-beta1。 Beta2 目前有另一个问题阻止在 UWP 中构建。
谢谢
NPadrutt
不完全确定您要做什么,但您可能需要使用 MvvmCross 作为框架在 UWP 应用程序中使用汉堡菜单导航页面,这是一个自定义演示器,它处理 ShowViewModel
方法,并在您的汉堡包容器视图中显示请求的 ViewModel 的关联视图。
好吧好尴尬。问题是无法解决 ViewModel 的视图。原因是我没有替换从页面到 views:MvxWindowsPage 的继承。
有了这个,一切都适用于默认页面演示者。
编辑:为了在应用程序 shell 中使用导航,这些页面需要是页面。因此,您可能必须重写 Appshell 中的导航,或者可能不会将所有页面调整为 MvxPage。
我参考了 this Whosebug 问题,关于 MVVM Light:
I am trying to have a hamburger menu style navigation (see this sample). app by Microsoft on an example of how to do this) to:
1- have a convenient solution shared across all my pages. The sample mentioned above uses an AppShell Page as the root of the app instead of a Frame, that encapsulates the navigation menu and some behavior of the back button. That would be ideal.
2- Use the MVVM-Light navigation service to handle all the navigation from my view model conveniently.
下面是 App.xml.Cs 如何在启动时初始化 shell 页面:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
var 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 AppShell to act as the navigation context and navigate to the first page
shell = new AppShell();
// Set the default language
shell.Language = ApplicationLanguages.Languages[0];
shell.AppFrame.NavigationFailed += OnNavigationFailed;
}
// 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.
var setup = new Setup(shell.AppFrame);
setup.Initialize();
var start = Mvx.Resolve<IMvxAppStart>();
start.Start();
}
// Ensure the current window is active
Window.Current.Activate();
}
事实是,只要我浏览 AppShell 提供的菜单,一切正常。但是来自 MVVM Cross 的 ShowViewModel 没有任何效果。 我认为如果将 shell 作为框架或在 AppShell 上设置的框架传递,应该没有任何区别。 有没有人知道我能做些什么,或者是否有一个带有 MVVM cross 的工作汉堡菜单的例子?
如果您需要更好的概述,该存储库在 GitHub 上是开源的。
https://github.com/Apply-Solutions/MoneyManager
我使用 MVVM Cross v4.0.0.0-beta1。 Beta2 目前有另一个问题阻止在 UWP 中构建。
谢谢 NPadrutt
不完全确定您要做什么,但您可能需要使用 MvvmCross 作为框架在 UWP 应用程序中使用汉堡菜单导航页面,这是一个自定义演示器,它处理 ShowViewModel
方法,并在您的汉堡包容器视图中显示请求的 ViewModel 的关联视图。
好吧好尴尬。问题是无法解决 ViewModel 的视图。原因是我没有替换从页面到 views:MvxWindowsPage 的继承。 有了这个,一切都适用于默认页面演示者。
编辑:为了在应用程序 shell 中使用导航,这些页面需要是页面。因此,您可能必须重写 Appshell 中的导航,或者可能不会将所有页面调整为 MvxPage。