Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 2.39 KB

File metadata and controls

64 lines (52 loc) · 2.39 KB

Simple MVVM Toolkit Express: Xamarin Forms Sample

  1. To use this sample, instsall the Xamarin tools for Visual Studio 2015.
  1. Create a new Cross-Platform project using Visual Studio 2015 or higher
  • Target Framework: Xamarin.Forms Portable
  • Update NuGet packages
  • Build the solution
  1. Add the SimpleMvvmToolkit.Express NuGet package to each project

  2. Use Code Snippets Manager to add the Simple Mvvm C# code snippets

  3. Add Models folder

  • Add Customer class
  • Use mvvmprop snippet to add properties
    • CustomerId, CustomerName, City
  1. Add Services folder
  • Interface: ICustomerService
  • Class: MockCustomerService
  1. Add ViewModels folder
  • MainPageViewModel
  • CustomerViewModel
  1. Add Locators folder
  • Add NuGet package: SimpleInjector
  • Add ViewModelLocator class
  1. Add ViewModelLocator to app resources
  • Remove existing App.cs file
  • Add new Forms Xaml Page named App.cs
  • Replace ContentPage with Application
  • Add a Resource for ViewModelLocator with the key "Locator"
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:locators="clr-namespace:SimpleMvvmSamples.XamarinForms.Locators;assembly=SimpleMvvmSamples.XamarinForms"
            x:Class="SimpleMvvmSamples.XamarinForms.App">
  <Application.Resources>
    <ResourceDictionary>
      <locators:ViewModelLocator x:Key="Locator"/>
    </ResourceDictionary>
  </Application.Resources>
</Application>
  1. Add Views folder
  • Add Forms Xaml Page: CustomerView
  • Add StackLayout with a BindingContext of MainPageViewModel
  • Add a Grid within the StackLayout with a BindingContext of CustomerViewModel
  1. Build and deploy each target project
  • Clicking the New Customer button should populate the Entry controls