MVVM Cross Notes

MVVM Cross Android

MVVM Cross Android Binding

/Resources/Values

eg:

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="MvxBinding">
    <attr name="MvxBind" format="string"/>
    <attr name="MvxLang" format="string"/>
  </declare-styleable>
  <declare-styleable name="MvxControl">
    <attr name="MvxTemplate" format="string"/>
  </declare-styleable>
  <declare-styleable name="MvxListView">
    <attr name="MvxItemTemplate" format="string"/>
    <attr name="MvxDropDownItemTemplate" format="string"/>
  </declare-styleable>
  <item type="id" name="MvxBindingTagUnique"/>
  <declare-styleable name="MvxImageView">
    <attr name="MvxSource" format="string"/>
  </declare-styleable>
</resources>

Data Bindings

Two-Way

This binding mode transfers values in both directions
Changes in both View and ViewModel properties are monitored - if either changes, then the other will be updated.

One-Time

  • This binding mode transfers values from ViewModel to View
  • Not very commonly used, but can be useful for fields which are configurable but which don't tend to change after they have initially been set.
  • One-Time binding when setting static text from language files - this is because it's common for the user to select a language, but once chosen, it's uncommon for the user to then change that language.

Data Binding

2 way Data Binding Syntax using MVVM Cross and Android

local:MvxBind="Text SubTotal"

What this line means is:

data-bind:

the property Text on the View to the property SubTotal on the DataContext - which in this case will be a TipViewModel

so:

whenever the TipViewModel calls RaisePropertyChanged on SubTotal then the View should update and whenever the user enters text into the View then the SubTotal value should be set on the TipViewModel

this is TwoWay binding

details and original tutorial

MVVM Cross IOS

How to make Visual Studio IOS Designer and MVVM Cross Work together

  • instead of modifying the .xib files in Xcode, you can use the VS Story Board Designer using the 2nd method listed in this post.
  • An .xib editor for visual studio is coming by Xamarin in the future