嘿大家我正在使用Autofac(MVVM)我的问题是如何通过单击弹出屏幕中的确定按钮从DisplayAlert Popup重定向到另一个页面?由于显示警报在我的视图和我的ViewModel中,因此ICommand导航到另一个页面是导航器。
PushAsync<PageViewModel>();
我的一些代码剪辑:
的ViewModels
public class HomePageViewModel : ViewModelBase
{
private readonly INavigator _navigator;
public HomePageViewModel(INavigator navigator)
{
_navigator = navigator;
CmdInvites = new Command(Cmdinvites);
}
public ICommand CmdInvites { get; private set; }
//Invite PhoneBook
private void Cmdinvites()
{
_navigator.PushAsync<PhoneContactViewModel>();
}
}
zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread(async () => {
// Stop analysis until we navigate away so we don't keep reading barcodes
zxing.IsAnalyzing = false;
// Show an alert
await DisplayAlert("Scanned Barcode", result.Text, "OK");
// Navigate away
await Navigation.PopAsync();
<-------------this is where i want to redirect the {Binding CmdInvites}
});
感谢您抽出时间阅读我的帖子。
答案 0 :(得分:0)
您可以使用另一个 DisplayAlert 方法构造函数,如下所示:
Device.BeginInvokeOnMainThread(async () => {
// Stop analysis until we navigate away so we don't keep reading barcodes
zxing.IsAnalyzing = false;
// Show an alert
if(await DisplayAlert("Scanned Barcode", result.Text, "Accept","Cancel"))
{
// Navigate away
await Navigation.PopAsync();
<-------------this is where i want to redirect the {Binding CmdInvites}
}
});