ReactiveProperty.XamarinAndroid is MVVM support library for ReactiveProperty + Xamarin.Android environment.
- Xamarin is here.
- 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.
This ViewModel class is here.
public class VM
{
// ViewModel Property
public ReactiveProperty<string> Output { get; set; }
public VM() { this.Output = new ReactiveProperty(); }
}
var vm = new VM();
this.FindViewById<TextView>(Resource.Id.TextView)
.SetBinding(
x => x.Text, // select target property
vm.Output); // source property
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
SetCommand extension methods can be found in IObservable .
this.FindViewById<Button>(Resource.Id.Button)
.ClickAsObservable()
.SetCommand(vm.AlertCommand);
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