繁体   English   中英

ViewModel中的Navigation.PopModalAsync()ArgumentOutOfRangeException

[英]Navigation.PopModalAsync() in ViewModel ArgumentOutOfRangeException

我正在尝试向用户显示生日消息。 他们使用此帐户登录后,我会立即打开页面。

protected override async void OnDisappearing()
{
    await Navigation.PushModalAsync(new BirthdayPage(Navigation));
}

然后,我在BirthdayPageViewModel中,尝试将命令设置为Navigation.PopModalAsync(),以便单击关闭按钮时它将关闭页面。

CloseBirthdayPageCommand = new Command(async () => await navigation.PopModalAsync());

出于某种原因,当我这样做时,它将引发ArgumentOutOfRangeException而不是关闭我的BirthdayPage。

我觉得这很奇怪,因为我可以将OnDisappearing方法更改为此,并且可以很好地关闭它。

protected override async void OnDisappearing()
{
    await Navigation.PushModalAsync(new BirthdayPage(Navigation));
    await Navigation.PopModalAsync();
}

当然可以,但是我希望用户能够通过单击按钮来关闭页面。 任何建议,不胜感激。

我可以通过将BirthdayPageViewModel命令行切换为

CloseBirthdayPageCommand = new Command(async () => await App.Current.MainPage.Navigation.PopModalAsync());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM