Skip to content

Instantly share code, notes, and snippets.

@Haosvit
Last active September 13, 2016 04:32
Show Gist options
  • Save Haosvit/64cf5c7beddeba1bcb9ce51e7ec3ee63 to your computer and use it in GitHub Desktop.
Save Haosvit/64cf5c7beddeba1bcb9ce51e7ec3ee63 to your computer and use it in GitHub Desktop.

MVVMCross Binding

xmlns:local="http://schemas.android.com/apk/res-auto"

Binds Android.Views
Text Text,Number (can be formatted: Ex local:MvxBind="Text Format('Now: {0:hhmmss}', Time)"); // TimeSpan Time
Click ICommand
Value DateTime, Time
ItemsSource MvxSpinner, MvxListView, MvxLinearLayout, MvxFrameLayout, MvxRadioGroup
ItemClick MvxListView Item
SelectedItem MvxSpinner Item, MvxRadioGroup Item
Progress SeekBar (binds with a number)

####MvxNotifyPropertyChanged A class extends MvxNotifyPropertyChanged will be able to raise property changed (RaisePropertyChanged) ex: // In ViewModel

  {
    public class PersonViewModel : MvxNotifyPropertyChanged
    {
        private string _firstName;
        public string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; RaisePropertyChanged(() => FirstName); }
        }
    
        private string _lastName;
        public string LastName
        {
            get { return _lastName; }
            set { _lastName = value; RaisePropertyChanged(() => LastName); }
        }
      }
      
      private PersonViewModel _firstPerson = new PersonViewModel()
      {
          FirstName = "Fred",
          LastName = "Flintstone"
      };
      public PersonViewModel FirstPerson
      {
          get { return _firstPerson; }
          set { _firstPerson = value; RaisePropertyChanged(() => FirstPerson); }
      }
    }

####ValueConverter - binding XXXValueConverter : MvxValueConverter

  • Define:
    • override Convert
    • override ConvertBack
  • Usage:
    • local:MvxBind="Text Value, Converter=PlusTen

####If - binding local:MvxBind="Text If(TestVal1 > TestVal2, 'First', 'Second')" // TestVal1 and TestVal2 are other bindings on other views

####Math - binding local:MvxBind="Text TestVal1 + '+' + TestVal2 + '=' + (TestVal1 + TestVal2)" // TestVal1 and TestVal2 are other bindings on other views

####RatingBar - binding local:MvxBind="NumStars OutOf; Rating Rating; StepSize StepSize"; // In ViewModel OutOf: Number of stars Rating: rating StepSize: step size

####Mvx.MvxListview - binding

  <Mvx.MvxListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    local:MvxItemTemplate="@layout/listitem_mainmenu"
    local:MvxBind="ItemsSource MenuItems" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment