-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug 🐞
When using BindCommand, the ViewModel passed to the withParameter expression can be different from the ViewModel the command is invoked on.
Step to reproduce
- Use a
ReactiveUI.Winforms.ViewModelControlHostwithCacheViews = true. - Set a ViewModel.
- Set a new ViewModel of the same type.
- The command parameter is computed from the old ViewModel.
Reproduction repository
https://github.com/xackus/ReactiveUiBindCommandRepro
Expected behavior
The ViewModel passed to the withParameter expression is the same as the ViewModel the command is invoked on.
Screenshots 🖼️
No response
IDE
Visual Studio 2022
Operating system
Windows
Version
11
Device
PC
ReactiveUI Version
20.1.63
Additional information ℹ️
BindCommand internally uses Reflection.ViewModelWhenAnyValue for the subscription, which despite taking a ViewModel parameter, does not use it.
The only place where the ViewModel passed to BindCommand is actually used is when invoking the withParameter expression.
I find it very confusing that the Bind*(View, ViewModel, ...) family of functions seems to sometimes use the ViewModel that was passed in, and sometimes instead extracts the ViewModel from the View.
In my case I need the second behavior, because I reuse the View when possible. But then why pass in the ViewModel at all?
I haven't been using ReactiveUI for very long. Was the approach changed here some time ago?