Permalink
Browse files

Make TargetActionCommandBinder compatible with Monotouch

  • Loading branch information...
1 parent a255c1f commit 55166b5c9d8676152ea2e4c4e8b333d61fb5118e @paulcbetts paulcbetts committed Mar 25, 2013
Showing with 8 additions and 2 deletions.
  1. +8 −2 ReactiveUI.Cocoa/TargetActionCommandBinder.cs
@@ -58,14 +58,20 @@ public IDisposable BindCommandToObject(ICommand command, object target, IObserva
});
var sel = new Selector("theAction:");
+#if UIKIT
+ var ctl = (UIControl)target;
+ ctl.AddTarget(ctlDelegate, sel, UIControlEvent.TouchUpInside);
+ var actionDisp = Disposable.Create(() => ctl.RemoveTarget(ctlDelegate, sel, UIControlEvent.TouchUpInside));
+#else
Reflection.GetValueSetterOrThrow(target.GetType(), "Action")(target, sel);
-
var targetSetter = Reflection.GetValueSetterOrThrow(target.GetType(), "Target");
targetSetter(target, ctlDelegate);
+ var actionDisp = Disposable.Create(() => targetSetter(target, null));
+#endif
var enabledSetter = Reflection.GetValueSetterForProperty(target.GetType(), "Enabled");
var disp = new CompositeDisposable(
- Disposable.Create(() => targetSetter(target, null)),
+ actionDisp,
commandParameter.Subscribe(x => latestParam = x),
Observable.FromEventPattern<EventHandler, EventArgs>(x => command.CanExecuteChanged += x, x => command.CanExecuteChanged -= x)
.Select(_ => command.CanExecute(latestParam))

0 comments on commit 55166b5

Please sign in to comment.