Click on button i.e. .Activated not invoked once OrderOut is called

回眸只為那壹抹淺笑 提交于 2021-01-29 19:24:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!