条形码扫描仪页面导航问题
Bar code scanner page navigation issue
我有这个条形码教程 reader/scanner 我遵循了。在 ScannerPage
中,当我单击一个按钮时,它会打开 scanner
,读取后,它会使用 API 和 return 将结果传递给数据库 [=11] =].
我有这个错误 Page must not already have a parent
但我不知道为什么。如何解决这个问题?
private async void Button_Clicked(object sender, EventArgs e)
{
scanPage = new ZXingScannerPage();
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread( async() =>
{
await Navigation.PopAsync();
//send something using WEB API
});
};
await Navigation.PushAsync(scanPage);
}
你是await Navigation.PushAsync(scanPage);
两次。
改为:
private async void Button_Clicked(object sender, EventArgs e)
{
scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread( async() =>
{
await Navigation.PopAsync();
//send something using WEB API
});
};
await Navigation.PushAsync(scanPage);
}
您正在推送 scanPage 两次
scanPage = new ZXingScannerPage();
// this is not needed
// await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread( async() =>
{
await Navigation.PopAsync();
//send something using WEB API
});
};
// navigate here, AFTER you have defined your OnScanResult handler
await Navigation.PushAsync(scanPage);
我有这个条形码教程 reader/scanner 我遵循了。在 ScannerPage
中,当我单击一个按钮时,它会打开 scanner
,读取后,它会使用 API 和 return 将结果传递给数据库 [=11] =].
我有这个错误 Page must not already have a parent
但我不知道为什么。如何解决这个问题?
private async void Button_Clicked(object sender, EventArgs e)
{
scanPage = new ZXingScannerPage();
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread( async() =>
{
await Navigation.PopAsync();
//send something using WEB API
});
};
await Navigation.PushAsync(scanPage);
}
你是await Navigation.PushAsync(scanPage);
两次。
改为:
private async void Button_Clicked(object sender, EventArgs e)
{
scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread( async() =>
{
await Navigation.PopAsync();
//send something using WEB API
});
};
await Navigation.PushAsync(scanPage);
}
您正在推送 scanPage 两次
scanPage = new ZXingScannerPage();
// this is not needed
// await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread( async() =>
{
await Navigation.PopAsync();
//send something using WEB API
});
};
// navigate here, AFTER you have defined your OnScanResult handler
await Navigation.PushAsync(scanPage);