Skip to content

Latest commit

 

History

History
74 lines (57 loc) · 2.05 KB

README-Android.md

File metadata and controls

74 lines (57 loc) · 2.05 KB

ReactiveProperty.XamarinAndroid

ReactiveProperty.XamarinAndroid is MVVM support library for ReactiveProperty + Xamarin.Android environment.

Features

  • OneWay and TwoWay databinding, between View's property and ReactiveProperty.
  • IList, ObservableCollection and ReadOnlyObservableCollection convert to IListAdapter.
  • View classes(ex, Button, TextView...) event provide extension method "EventName"AsObservable.

DataBinding

This ViewModel class is here.

public class VM
{
  // ViewModel Property
  public ReactiveProperty<string> Output { get; set; }

  public VM() { this.Output = new ReactiveProperty(); }
}

OneWay databinding.

var vm = new VM();

this.FindViewById<TextView>(Resource.Id.TextView)
  .SetBinding(
    x => x.Text, // select target property
    vm.Output); // source property

TwoWay databinding

var vm = new VM();

this.FindViewById<EditText>(Resource.Id.EditText)
  .SetBinding(
    x => x.Text, // select target property
    vm.Output,  // source property
    x => x.TextChangedAsObservable().ToUnit()); // update source trigger

Command binding

SetCommand extension methods can be found in IObservable .

this.FindViewById<Button>(Resource.Id.Button)
  .ClickAsObservable()
  .SetCommand(vm.AlertCommand);

Collection binding

Collection type can convert to IListAdapter.

public class VM
{
  public ReadOnlyReactiveCollection<string> Values { get; private set; }
}


var vm = new VM();
this.FindViewById<ListView>(Resource.Id.ListView)
    .Adapter = vm.Values.ToAdapter(
      (index, value) => LayoutInflator.FromContext(this).Inflate(Android.Resource.Layout.SimpleListItem1) // create view
      (index, value, view) => view.FindViewById<TextView>(Android.Resource.Id.Text1).Text = value, // setup view
      (index, value) => value.GetHashCode()); // generate id

many many many... extension methods

here