2

I have created a new solution for my MvvmCross app that supported Windows Store and I want to support UWP on Windows 10. I have moved over the PCL successfully, but I am having problems getting the basic UWP app working using a sample provided by MS (NavigationMenu) which uses the SplitView and the AppShell pattern they are recommending for the new navigation/command model. I referenced a helpful blog post (http://stephanvs.com/implementing-a-multi-region-presenter-for-windows-10-uwp-and-mvvmcross/), which gave me some guidance on how to integrate mvvmcross into the AppShell, but startup is failing because the AppShell does not have a valid Frame defined. Frame is a read-only property, and I have been unable to see where this is being set up.

I am using the standard AppShell implementation from the NavigationMenu with the following changes as recommended in the blog post:

public sealed partial class AppShell : MvxWindowsPage // was Page

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

Except for code after the error, there are no differences in the setup. In looking at the MvxWindowsPage implementation, there doesn't seem to be anything special as it still invokes the Page initialization. Is there something obvious I am missing?

4

2 回答 2

2

因此,博客文章的链接是正确的,换句话说,您需要使用 MvvmCross 中的 MultiRegions 才能使其正常工作。但是博文没有显示的是一个完整的工作版本......

我在我的 github 上添加了一个: https ://github.com/Depechie/MvvmCrossUWPSplitView

就像我在评论中所说的那样,一些要带走的指针。您的 SplitView 将出现的视图需要有一个属性来返回一个有效的 Frame 以在注入新视图时查找。这可以像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

于 2015-11-21T00:34:49.380 回答
1

我了解您尝试使用 Microsoft 提供的 SplitView 模板做什么。然而,由 MvvmCross 和 UWP 管理的事物之间存在不匹配。

默认情况下,MvvmCross 根据命名约定将 ViewModels 映射到 Views。您要做的是使用Windows.UI.Xaml.Controls.Page不符合默认 MvvmCross 约定的视图“AppShell”(派生自 )。

我选择实现此 SplitView (Hamburger) 功能的方式是AppShell完全删除提供的类。然后我创建了一个名为的新视图HomeView(因为我有一个名为 的 ViewModel HomeViewModel)并在那里添加了 SplitView 控件,如您上面提到的帖子中所述。

为了完整起见,我按照您的要求使用App.xaml.csand创建了一个要点。HomeView.xaml你可以在这里找到它们:https ://gist.github.com/Stephanvs/7bb2cdc9dbf15cb7a90f

于 2015-11-21T01:01:03.730 回答