Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ public IReactiveBinding<TView, TProp> BindCommand<
{
ArgumentExceptionHelper.ThrowIfNull(vmProperty);
ArgumentExceptionHelper.ThrowIfNull(controlProperty);
ArgumentExceptionHelper.ThrowIfNull(withParameter);
Comment thread
xackus marked this conversation as resolved.

var vmExpression = Reflection.Rewrite(vmProperty.Body);
var controlExpression = Reflection.Rewrite(controlProperty.Body);
var parameterExpression = Reflection.Rewrite(withParameter.Body);

var source = Reflection.ViewModelWhenAnyValue(viewModel, view, vmExpression).Cast<TProp>();
var parameterObservable = Reflection.ViewModelWhenAnyValue(viewModel, view, parameterExpression).Cast<TParam>();

var bindingDisposable = BindCommandInternal<TView, TProp, TParam, TControl>(
source,
view,
controlExpression,
withParameter.ToObservable(viewModel),
parameterObservable,
toEvent);

return new ReactiveBinding<TView, TProp>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using ReactiveUI.Tests.Utilities.Logging;
using ReactiveUI.Tests.Wpf.Mocks;
using ReactiveUI.Tests.Xaml.Mocks;

namespace ReactiveUI.Tests.Wpf;

Expand Down Expand Up @@ -272,4 +273,22 @@ public async Task ViewModelShouldBeGarbageCollectedWhenOverwritten()

await Assert.That(weakRef.IsAlive).IsFalse();
}

[Test]
public async Task CommandParameterIsCorrectAfterViewModelReassignment()
{
var vm = new CommandBindingViewModel { Value = 1 };
var view = new CommandBindingView { ViewModel = vm };

var received = 0;
view.ViewModel.Command1 = ReactiveCommand.Create<int, int>(i => received = i);

Comment thread
xackus marked this conversation as resolved.
Outdated
var binding = new CommandBinderImplementation().BindCommand(vm, view, vm => vm.Command1, v => v.Command1, vm => vm.Value, nameof(CustomClickButton.CustomClick));
Comment thread
xackus marked this conversation as resolved.

view.ViewModel = new CommandBindingViewModel { Value = 2 };

view.Command1.RaiseCustomClick();

await Assert.That(received).IsEqualTo(2);
Comment thread
xackus marked this conversation as resolved.
Outdated
}
}