reactiveui/ReactiveUI — pull request #478 by paulcbetts (2014-01-08 07:29:23+00:00)
Title: Improved List Adapter Improvements

What do you think about this @onovotny? I think this can simplify how list adapters work a lot.

### Complex scenario (layout-based tile)

Basically, the idea is, if you have a layout-based tile, you create a subclass of `ReactiveViewHost`, which is where you put all the setup for binds (similar to how you'd have UserControl in XAML):

```cs
public class WatchListItemView : ReactiveViewHost
{
public WatchListItemView(Context ctx, ViewGroup parent) : base(ctx, Resource.Layout.WatchListItem, parent)
{
this.Bind(ViewModel, vm => vm.Symbol, v => v.Symbol.Text);
this.OneWayBind(ViewModel, vm => vm.Price, v => v.Price.Text, v => string.Format("{0:0.00}", v));
this.OneWayBind(ViewModel, vm => vm.LastChange, v => v.LastChange.Text, v => string.Format("{0:0.00}", v));
this.OneWayBind(ViewModel, vm => vm.PercentChange, v => v.PercentChange.Text, v => string.Format("{0:P2}", v));
this.OneWayBind(ViewModel, vm => vm.DayOpen, v => v.Open.Text, v => string.Format("{0:0.00}", v));
this.OneWayBind(ViewModel, vm => vm.DayHigh, v => v.High.Text, v => string.Format("{0:0.00}", v));
this.OneWayBind(ViewModel, vm => vm.DayLow, v => v.Low.Text, v => string.Format("{0:0.00}", v));
}

public TextView Symbol { get; private set; }
public TextView Price { get; private set; }
public TextView LastChange { get; private set; }
public TextView PercentChange { get; private set; }
public TextView Open { get; private set; }
public TextView High { get; private set; }
public TextView Low { get; private set; }
}
```

In the layout-based scenario, the adapter gets simplified a lot too:

```cs
var adapter = new ReactiveListAdapter(
ViewModel.Stocks,
(viewModel, parent) => new WatchListItemView(this, parent));
```

### Simple layout (i.e. Just A View)

This doesn't go as well, but I also think it's a less common case:

```cs
var adapter = new ReactiveListAdapter(
ViewModel.ListOfStrings,
(viewModel, parent) => new TextView(this),
(viewModel, view) => ((TextView)view).Text = viewModel);
```

I wanted to make the initializer typed based on the return value of the creator, but it made the former case uglier. People will just have to Deal™.

Thoughts?