Question

I'm trying to learn ReactiveUI for a Xamarin.iOS project and I'm stuck on what should be a simple task. I am unable to bind a button click to a ReactiveCommand in the same way I can in my companion Xamarin.Android project. Here is the Android code that works fine:

this.BindCommand (ViewModel, x => x.ClickMe, view => view._button);

Here is the same pattern used in iOS:

this.BindCommand (ViewModel, x => x.ClickMe, view => view.GetForecastButton);

However, in iOS I get the following warning:

"Couldn't find a Command Binder for MonoTouch.UIKit.UIButton"

Does anyone know what I'm doing wrong? The astonishing thing is that I've looked up dozens of ReactiveUI iOS examples and I still haven't found one that has even a single button in the app. They all do something like show text from a bound property or show a UITableView from a collection in the ViewModel. I'm sure there is a more complete iOS example out there and if anyone knows of one please include in your answer. Many thanks.

Was it helpful?

Solution

You're doing everything correctly, but I believe you're being trolled by a Xamarin.iOS bug that affects ReactiveUI, where Type.GetType won't load assemblies. Paste this into your AppDelegate:

https://github.com/paulcbetts/starter-mobile/blob/master/Starter-iOS/AppDelegate.cs#L35

        // NB: GrossHackAlertTiem™:
        //
        // Monotouch appears to not load assemblies when you request them 
        // via Type.GetType, unlike every other platform (even 
        // Xamarin.Android). So, we've got to manually do what RxUI and 
        // Akavache would normally do for us
        var r = RxApp.MutableResolver;
        (new ReactiveUI.Cocoa.Registrations()).Register((f,t) => r.Register(f, t));
        (new ReactiveUI.Mobile.Registrations()).Register((f,t) => r.Register(f, t));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top