8

I'm switching to the latest version of ReactiveUI (7.0) and I'm running into some incompatibilities and would like to know the suggested way to handle this:

ReactiveUI 6.x

Texts.Events().MouseUp
     .InvokeCommand(ViewModel, x => x.DoSomething);

This now throws an exception:

Command requires parameters of type System.Reactive.Unit, but received parameter of type System.Windows.Input.MouseButtonEventArgs.

I fixed this by using the following code, but is this the right way?

Texts.Events().MouseUp
     .Select(x => Unit.Default)
     .InvokeCommand(ViewModel, x => x.DoSomething);
Niek Jannink
  • 1,056
  • 2
  • 12
  • 24
  • Did you figure out what was causing the problem? I have the same problem. – Michal Sep 24 '17 at 07:53
  • 3
    The argument that the command was expection was Unit, meaning a command without an input argument which in the case of ReactiveUI is a ReactiveCommand. Thats why in the example above you have to 'convert' the MouseButtonEventArgs from the event to a Unit. For this I created a helper extension method ToSignal: `public static IObservable ToSignal(this IObservable source) => source.Select(_ => Unit.Default);` – Niek Jannink Sep 26 '17 at 18:51
  • That was obvious... thanks. Oh, also, you should post an answer to your own question and accept it, rather than commenting ;) – Morgan Touverey Quilling Oct 31 '17 at 10:35

1 Answers1

2

The argument that the command was expection was Unit, meaning a command without an input argument which in the case of ReactiveUI is a ReactiveCommand. Thats why in the example above you have to 'convert' the MouseButtonEventArgs from the event to a Unit. For this I created a helper extension method ToSignal:

public static IObservable<Unit> ToSignal<TDontCare>(this IObservable<TDontCare> source) 
    => source.Select(_ => Unit.Default);

\\ The subscription will be then
Texts.Events().MouseUp
     .ToSignal()
     .InvokeCommand(ViewModel, x => x.DoSomething);
Niek Jannink
  • 1,056
  • 2
  • 12
  • 24