从头开始为Windows 8.1创建MvvmCross Store应用程序的过程? [英] Procedure for creating an MvvmCross Store application for Windows 8.1 from scratch?
问题描述
使用Visual Studio 2013,我基于 MvvmCross 创建了一个用于Windows 8.1的新Windows应用商店应用.
Using Visual Studio 2013, I am creating a new Windows Store application for Windows 8.1 based on MvvmCross.
我首先根据 Core.txt 待办事项文件中的说明创建带有视图模型的PCL .Core 类库.
I first create my PCL .Core class library with view models according to the instructions in the Core.txt to-do file.
接下来,我现在按照 Windows Store UI.txt 待办事项文件中的说明创建我的 .Store 应用程序.我确实想使用导航框架,所以我要用基本页面 FirstView.xaml
替换FirstView.xaml
页面.
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
.
根据说明,LayoutAwarePage
类应该继承MvxStorePage
,但是由于LayoutAwarePage.cs
不再包含在VS2013/8.1 Store项目中,因此我将FirstView.xaml
页面更改为MvxStorePage
类型:
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>
进行此更改后,当我启动应用程序时会显示 FirstView ,但是视图模型绑定不起作用!在Windows Store 8.1应用中设置MvvmCross视图模型绑定的正确过程是什么?
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?
推荐答案
似乎我忘记了 Windows Store UI.txt 待办事项文件中的一部分说明:
Seems I forgot one part of the instructions in the Windows Store UI.txt to-do file:
添加一个视图文件夹和一个视图-基于BasicPage的xaml.cs和.xaml-这会将5个文件添加到Common文件夹中.
-将Common/LayoutAwarePage.cs继承更改为Cirrious.MvvmCross.WindowsStore .Views.MvxStorePage
-更改Common/LayoutAwarePage.cs-删除OnNavigatedTo和OnNavigatedFrom处理程序
-为您的Xaml添加一些内容-例如<TextBlock Grid.Row="1" Text="{Binding Hello}"/>
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}"/>
如果我从FirstView.xaml.cs
文件中删除OnNavigatedTo
和OnNavigatedFrom
替代,则FirstViewModel
将正确绑定到FirstView
.
If I remove the OnNavigatedTo
and OnNavigatedFrom
overrides from the FirstView.xaml.cs
file, FirstViewModel
will be correctly bound to FirstView
.
据我所知,Windows 8.1上Windows Store应用程序的说明应为:
So, as far as I can tell, the instructions for Windows Store apps on Windows 8.1 should be:
- 在每个 view .xaml 文件中,将
<Page>
更改为<views:MvxStorePage>
. - 在每个 view .xaml.cs 文件中,删除
OnNavigatedTo
和OnNavigatedFrom
替代.
- In every view .xaml file, change
<Page>
to<views:MvxStorePage>
. - In every view .xaml.cs file, delete the
OnNavigatedTo
andOnNavigatedFrom
overrides.
编辑
此外,为了避免视图模型混淆,最好从 .xaml.cs 文件中删除DefaultViewModel
属性和关联的defaultViewModel
字段,并同时删除来自 .xaml 文件中<views:MvxStorePage>
标记的DataContext
属性,因为无论如何,相关的DataContext
都将由 MvvmCross 设置.
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.
这篇关于从头开始为Windows 8.1创建MvvmCross Store应用程序的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!