MvvmCross 4 支持 UWP,AppShell 缺少框架

MvvmCross 4 support for UWP, AppShell missing Frame

我为我的 MvvmCross 应用程序创建了一个支持 Windows Store 的新解决方案,我想在 Windows 10 上支持 UWP。我已经成功移动到 PCL,但是我在使用 MS (NavigationMenu) 提供的示例让基本 UWP 应用程序工作时遇到问题,该示例使用 SplitView 和他们为新 navigation/command 模型推荐的 AppShell 模式。我参考了一个有用的博客 post (http://stephanvs.com/implementing-a-multi-region-presenter-for-windows-10-uwp-and-mvvmcross/),它给了我一些关于如何将 mvvmcross 集成到 AppShell 的指导,但是启动失败,因为 AppShell 没有定义有效的框架。 Frame 是只读的 属性,我一直无法看到它的设置位置。

我正在使用来自 NavigationMenu 的标准 AppShell 实现,并按照博客 post 中的建议进行了以下更改:

public sealed partial class AppShell : MvxWindowsPage // was Page

public Frame AppFrame { get { return this.Frame; } } // was this.frame

除了错误后的代码外,设置上没有差异。在查看 MvxWindowsPage 实现时,似乎没有什么特别的,因为它仍然调用 Page 初始化。有什么明显的我想念的吗?

所以博文的 link 是正确的,换句话说,您需要使用 MvvmCross 中的 MultiRegions 才能使其正常工作。 但是博文没有显示完整的工作版本...

我在 github 此处添加了一个: https://github.com/Depechie/MvvmCrossUWPSplitView

一些要点,就像我在评论中所说的那样。 SplitView 所在的视图需要有一个 属性 到 return 的有效框架,以便在注入新视图时查找。这可以 return 像这样 return (Frame)this.WrappedFrame.UnderlyingControl; 在此处的代码中找到 https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/FirstView.xaml.cs#L13

您想要在 SplitView 中加载的所有视图都需要引用您在该 SplitView 中定义的区域,在我的例子中,我将其命名为 FrameContent,如此处所示 https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/FirstView.xaml#L48

因此,在所有要加载的视图中使用该名称作为区域属性,如此 [MvxRegion("FrameContent")] 此处示例 https://github.com/Depechie/MvvmCrossUWPSplitView/blob/master/MvvmCrossUWP.Win/Views/SecondView.xaml.cs#L7

我知道你想用 Microsoft 提供的 SplitView 模板做什么。然而,MvvmCross 和 UWP 管理的事物之间存在不匹配。

默认情况下,MvvmCross 根据命名约定将 ViewModel 映射到 View。您要做的是使用不遵守默认 MvvmCross 约定的视图 'AppShell'(派生自 Windows.UI.Xaml.Controls.Page)。

我选择实现此 SplitView(汉堡包)功能的方式是完全删除提供的 AppShell class。然后我创建了一个名为 HomeView 的新视图(因为我有一个名称为 HomeViewModel 的 ViewModel)并按照上面提到的 post 中的描述在其中添加了 SplitView 控件。

为了完整起见,我根据您的要求创建了一个包含 App.xaml.csHomeView.xaml 的 Gist。您可以在这里找到它们:https://gist.github.com/Stephanvs/7bb2cdc9dbf15cb7a90f