问题
The Button.Activated or Button's Action is not getting called for some reason, which I can not find.
The code goes like this.
In the ViewController's constructor:
_whenActivated = this.WhenActivated(x => SetupBindings(x));
Then have a methods:
private void SetupBindings(CompositeDisposable disposables)
{
this.BindCommand(ViewModel,
vm => vm.ContinueCommand,
v => v._loginButton)
.DisposeWith(disposables);
Observable.FromEventPattern(
h => _cancelButton.Activated += h,
h => _cancelButton.Activated -= h)
.Subscribe(x => Cancel(disposables))
.DisposeWith(disposables);
Deactivated.Take(1).Subscribe(_ => _whenActivated?.Dispose());
}
private void Cancel(CompositeDisposable disposables)
{
ViewModel.CancelCommand.Execute().Subscribe().DisposeWith(disposables);
View.Window.OrderOut(null);
Console.WriteLine("Cancel clicked");
}
When I click the _cancelButton, first time the Cancel(...) gets called and it is ordered-out/or set the View.Window.IsVisible = false
. But when I bring it back using OrderFront
, the action on the cancel is not called again.
However there is another button (a checkbox) that gets the action, and it changes its state.
I suspect for some reason the .Activated
is disposed of. Could this be the reason? Then what should I do to prevent it?
Or, What am I missing here?
来源:https://stackoverflow.com/questions/63733962/click-on-button-i-e-activated-not-invoked-once-orderout-is-called