[Bug]: Inconsistent BindCommand
behaviour when reusing a View with a new ViewModel
#3970
Labels
BindCommand
behaviour when reusing a View with a new ViewModel
#3970
Describe the bug 🐞
When using
BindCommand
, the ViewModel passed to thewithParameter
expression can be different from the ViewModel the command is invoked on.Step to reproduce
ReactiveUI.Winforms.ViewModelControlHost
withCacheViews = true
.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 usesReflection.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 thewithParameter
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?
The text was updated successfully, but these errors were encountered: