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

标签 c# windows-store-apps mvvmcross windows-8.1

使用 Visual Studio 2013,我正在为基于 MvvmCross 的 Windows 8.1 创建一个新的 Windows 应用商店应用程序。

我首先根据 Core.txt 待办文件中的说明使用 View 模型创建我的 PCL .Core 类库。

接下来,我创建我的 .Store 应用程序,现在按照 Windows Store UI.txt 待办事项文件中的说明进行操作。我确实想使用导航框架,所以我将 FirstView.xaml 页面替换为 Basic Page FirstView.xaml

根据说明,LayoutAwarePage类应该继承MvxStorePage,但是由于LayoutAwarePage.cs不再包含在VS2013/8.1 Store中项目,我改为将我的 FirstView.xaml 页面更改为 MvxStorePage 类型:

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

通过此更改,当我启动应用程序时会显示 FirstView,但 View 模型绑定(bind)不起作用!在 Windows Store 8.1 应用程序中设置 MvvmCross View - View 模型绑定(bind)的正确过程是什么?

最佳答案

我似乎忘记了 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.
- 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}"/>

如果我删除 OnNavigatedToOnNavigatedFromFirstView.xaml.cs 覆盖文件,FirstViewModel将正确绑定(bind)到 FirstView .

因此,据我所知,Windows 8.1 上的 Windows 应用商店应用说明应该是:

  • 在每个查看 .xaml 文件中,更改 <Page><views:MvxStorePage> .
  • 在每个查看 .xaml.cs 文件中,删除 OnNavigatedToOnNavigatedFrom覆盖。

编辑 此外,为了避免 View 模型混淆,删除 DefaultViewModel 也是一个好主意。属性(property)及相关defaultViewModel .xaml.cs 文件中的字段,并删除 DataContext来自 <views:MvxStorePage> 的属性.xaml 文件中的标记,因为相关的 DataContext无论如何都会由 MvvmCross 设置。

关于c# - 从头开始为 Windows 8.1 创建 MvvmCross Store 应用程序的过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19925297/

相关文章:

c# - 为什么完全由CPU约束的进程与超线程一起工作会更好?

c# - MVVM DialogService替代品

c# - ItemGridView ItemClick on Windows Store App

windows-8 - 如何在 WinRT 中创建点击可移动控件?

c# - MvxCachingFragmentCompatActivity 刷新缓存 fragment

c# - 如何将下拉菜单与切换组绑定(bind)

c# - 在 C#、ANDROID 和 IPHONE 之间加密数据

c# - 如何在 C#/XAML Windows 应用商店 (Metro UI) 应用程序中混合浅色和深色主题?

ios - MVVMCross FluentLayout 相等水平间距

windows - 通过ViewModel自定义UWP ListViewItem