简体   繁体   English

从头开始为Windows 8.1创建MvvmCross Store应用程序的过程?

[英]Procedure for creating an MvvmCross Store application for Windows 8.1 from scratch?

Using Visual Studio 2013, I am creating a new Windows Store application for Windows 8.1 based on MvvmCross . 使用Visual Studio 2013,我将基于MvvmCross为Windows 8.1创建新的Windows应用商店应用程序。

I first create my PCL .Core class library with view models according to the instructions in the Core.txt to-do file. 我首先根据Core.txt待办事项文件中的说明创建带有视图模型的PCL .Core类库。

Next, I create my .Store application, now following the instructions in the Windows Store UI.txt to-do file. 接下来,我创建我的.Store应用程序,现在按照Windows Store UI.txt待办事项文件中的说明进行操作。 I do want to use the navigation framework, so I am replacing the FirstView.xaml page with a Basic Page FirstView.xaml . 我确实想使用导航框架,所以我用Basic Page FirstView.xaml替换FirstView.xaml页面。

According to the instructions, the LayoutAwarePage class should inherit MvxStorePage but since the LayoutAwarePage.cs is no longer included in VS2013/8.1 Store projects, I am instead changing my FirstView.xaml page to be an MvxStorePage type: 根据说明, LayoutAwarePage类应继承MvxStorePage但由于LayoutAwarePage.cs不再包含在VS2013 / 8.1 Store项目中,我改为将我的FirstView.xaml页面更改为MvxStorePage类型:

<views:MvxStorePage x:Name="pageRoot" x:Class="App.Store.Views.FirstView"
 ... >
...
</views:MvxStorePage>

With this change, FirstView is displayed when I start the app, but the view-model bindings do not work! 通过此更改,我启动应用程序时会显示FirstView ,但视图模型绑定不起作用! What would be the correct procedure for setting up the MvvmCross view-view model bindings in a Windows Store 8.1 app? 在Windows应用商店8.1应用中设置MvvmCross视图模型绑定的正确步骤是什么?

Seems I forgot one part of the instructions in the Windows Store UI.txt to-do file: 似乎我忘记了Windows Store UI.txt待办事项文件中的一部分说明:

Add a views folder and a view - xaml.cs and .xaml based on BasicPage - this will add 5 files to the Common folder. 添加一个views文件夹和一个视图 - 基于BasicPage的xaml.cs和.xaml - 这将添加5个文件到Common文件夹。
- Change the Common/LayoutAwarePage.cs inheritance to Cirrious.MvvmCross.WindowsStore.Views.MvxStorePage - 将Common / LayoutAwarePage.cs继承更改为Cirrious.MvvmCross.WindowsStore.Views.MvxStorePage
- Change the Common/LayoutAwarePage.cs - remove the OnNavigatedTo and OnNavigatedFrom handlers - 更改Common / LayoutAwarePage.cs - 删除OnNavigatedTo和OnNavigatedFrom处理程序
- Add some content for your Xaml - eg <TextBlock Grid.Row="1" Text="{Binding Hello}"/> - 为你的Xaml添加一些内容 - 例如<TextBlock Grid.Row="1" Text="{Binding Hello}"/>

If I remove the OnNavigatedTo and OnNavigatedFrom overrides from the FirstView.xaml.cs file, FirstViewModel will be correctly bound to FirstView . 如果我从FirstView.xaml.cs文件中删除OnNavigatedToOnNavigatedFrom覆盖,则FirstViewModel将正确绑定到FirstView

So, as far as I can tell, the instructions for Windows Store apps on Windows 8.1 should be: 所以,据我所知,Windows 8.1上Windows Store应用程序的说明应该是:

  • In every view .xaml file, change <Page> to <views:MvxStorePage> . 在每个视图.xaml文件中,将<Page>更改为<views:MvxStorePage>
  • In every view .xaml.cs file, delete the OnNavigatedTo and OnNavigatedFrom overrides. 在每个视图.xaml.cs文件中,删除OnNavigatedToOnNavigatedFrom覆盖。

EDIT Additionally, to avoid view-model mix-ups, it might also be a good idea to remove the DefaultViewModel property and associated defaultViewModel field from the .xaml.cs file, and also remove the DataContext attribute from the <views:MvxStorePage> tag in the .xaml file, since the relevant DataContext will anyhow be set by MvvmCross . 编辑此外,为了避免视图模型混淆,从.xaml.cs文件中删除DefaultViewModel属性和关联的defaultViewModel字段也是一个好主意,并且还从<views:MvxStorePage>标记中删除DataContext属性在.xaml文件中,因为无论如何都会由MvvmCross设置相关的DataContext

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM