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

我们两清 提交于 2019-12-11 13:19:07

问题


Using Visual Studio 2013, I am creating a new Windows Store application for Windows 8.1 based on MvvmCross.

I first create my PCL .Core class library with view models according to the instructions in the Core.txt to-do file.

Next, I create my .Store application, now following the instructions in the Windows Store UI.txt to-do file. I do want to use the navigation framework, so I am replacing the FirstView.xaml page with a Basic Page 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:

<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! What would be the correct procedure for setting up the MvvmCross view-view model bindings in a Windows Store 8.1 app?


回答1:


Seems I forgot one part of the instructions in the Windows Store UI.txt to-do file:

Add a views folder and a view - xaml.cs and .xaml based on BasicPage - this will add 5 files to the Common folder.
- Change the Common/LayoutAwarePage.cs inheritance to Cirrious.MvvmCross.WindowsStore.Views.MvxStorePage
- Change the Common/LayoutAwarePage.cs - remove the OnNavigatedTo and OnNavigatedFrom handlers
- Add some content for your Xaml - e.g. <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.

So, as far as I can tell, the instructions for Windows Store apps on Windows 8.1 should be:

  • In every view .xaml file, change <Page> to <views:MvxStorePage>.
  • In every view .xaml.cs file, delete the OnNavigatedTo and OnNavigatedFrom overrides.

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.



来源:https://stackoverflow.com/questions/19925297/procedure-for-creating-an-mvvmcross-store-application-for-windows-8-1-from-scrat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!