【问题标题】:MVVM Cross ShowViewModel doesn't work on UWP with customMVVM Cross ShowViewModel 不适用于具有自定义功能的 UWP
【发布时间】:2015-08-30 21:38:06
【问题描述】:

我参考this StackOverflow 问题,关于 MVVM Light:

我正在尝试使用汉堡菜单样式导航(请参阅此 样本)。由 Microsoft 提供的有关如何执行此操作的示例)到:

1- 在我的所有页面上共享一个方便的解决方案。样本 上面提到的使用 AppShell Page 作为应用程序的根目录 一个框架,它封装了导航菜单和一些行为 后退按钮。那将是理想的。

2- 使用 MVVM-Light 导航服务来处理所有导航 方便地从我的视图模型中。

下面是 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 作为 Frame 或在 AppShell 上设置的框架传递,应该没有任何区别。 有谁知道我能做些什么,或者是否有一个带有 MVVM cross 的汉堡菜单示例?

如果您需要更好的概览,该存储库在 GitHub 上是开源的。

https://github.com/Apply-Solutions/MoneyManager

我使用 MVVM Cross v4.0.0.0-beta1。 Beta2 目前还有一个问题会阻止在 UWP 中构建。

谢谢 帕德鲁特

【问题讨论】:

    标签: xamarin mvvmcross uwp


    【解决方案1】:

    不完全确定您要做什么,但您可能需要在使用 MvvmCross 作为框架的 UWP 应用程序中使用汉堡菜单导航页面时,是一个自定义演示者,它处理 ShowViewModel 方法,以及在汉堡容器视图中显示请求的 ViewModel 的关联视图。

    【讨论】:

      【解决方案2】:

      好吧,这很尴尬。问题是无法解析 ViewModel 的视图。原因是我没有替换从页面到视图的继承:MvxWindowsPage。 有了这个,一切都可以使用默认页面演示者。

      编辑:为了在应用程序外壳中使用导航,这些页面需要是 Pages。因此,您可能必须在 Appshell 中重写导航,或者可能不会将所有 Pages 调整为 MvxPage。

      【讨论】:

        猜你喜欢
        • 2021-01-11
        • 1970-01-01
        • 2017-02-07
        • 2021-09-21
        • 1970-01-01
        • 1970-01-01
        • 2017-02-09
        • 2021-03-27
        • 1970-01-01
        相关资源
        最近更新 更多