MVVM 的高階用法

要新增到第一個示例,為了測試應用程式中發生的導航語句,我們需要為 ViewModel 提供導航的掛鉤。為達到這個:

  • nuget 包中的 SpecFlow.Xamarin.Forms.IViewModel 新增到你的 PCL Xamarin.Forms 專案中
  • 在 ViewModel 中實現 IViewModel 介面。這將簡單地公開 Xamarin.Forms INavigation 屬性:
  • public class MainViewModel : INotifyPropertyChanged, IViewModel.IViewModel { public INavigation Navigation { get; set; }
  • 測試框架將選擇並管理內部導航
  • 你可以為你的應用程式使用任何 MVVM 框架(例如 XLabsMVVMCrossPrism 等等。只要在 ViewModel 中實現 IViewModel 介面,框架就會選擇它。