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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With