在 Xamarin Forms 应用程序中使用 ZXing Mobile
Using ZXing Mobile in Xamarin Forms app
目前正在尝试使用 ZXing Mobile for Xamarin Forms 构建应用程序。
编译的代码没有问题。但是在 Android 设备上尝试 运行 时,出现以下错误:
An unhandled exception occcured.
日志显示如下:
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
我是这样实现的:
scanButton.Clicked += async (sender, args) =>
{
var options = new MobileBarcodeScanningOptions
{
AutoRotate = false,
UseFrontCameraIfAvailable = false,
TryHarder = true
};
var scanPage = new ZXingScannerPage(options)
{
DefaultOverlayTopText = "Align the barcode within the frame",
DefaultOverlayBottomText = string.Empty,
DefaultOverlayShowFlashButton = true
};
// Navigate to our scanner page
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
await DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
};
还在 Android 的 Main activity 中添加了以下内容,就在 Xamarin 自己的 Init 之上:
ZXing.Net.Mobile.Forms.Android.Platform.Init();
感谢任何帮助。谢谢。
我试过你的代码,发现错误与导航有关。
您正在使用
await Navigation.PushAsync (scanPage);
确保从包含 NavigationPage 的页面调用此方法,否则会发生崩溃。
要解决此问题,您可以使用
await Navigation.PushModalAsync (scanPage);
相反,它不需要 NavigationPage,并且显示的结果页面将是模态的。使用上面的行,您还需要更改 "pop" 视图的方式。
await Navigation.PopModalAsync (true);
注:
这些消息即使在您工作时也会出现在日志中。
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
希望对您有所帮助。-
目前正在尝试使用 ZXing Mobile for Xamarin Forms 构建应用程序。
编译的代码没有问题。但是在 Android 设备上尝试 运行 时,出现以下错误:
An unhandled exception occcured.
日志显示如下:
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
我是这样实现的:
scanButton.Clicked += async (sender, args) =>
{
var options = new MobileBarcodeScanningOptions
{
AutoRotate = false,
UseFrontCameraIfAvailable = false,
TryHarder = true
};
var scanPage = new ZXingScannerPage(options)
{
DefaultOverlayTopText = "Align the barcode within the frame",
DefaultOverlayBottomText = string.Empty,
DefaultOverlayShowFlashButton = true
};
// Navigate to our scanner page
await Navigation.PushAsync(scanPage);
scanPage.OnScanResult += (result) =>
{
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
await DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
};
还在 Android 的 Main activity 中添加了以下内容,就在 Xamarin 自己的 Init 之上:
ZXing.Net.Mobile.Forms.Android.Platform.Init();
感谢任何帮助。谢谢。
我试过你的代码,发现错误与导航有关。
您正在使用
await Navigation.PushAsync (scanPage);
确保从包含 NavigationPage 的页面调用此方法,否则会发生崩溃。
要解决此问题,您可以使用
await Navigation.PushModalAsync (scanPage);
相反,它不需要 NavigationPage,并且显示的结果页面将是模态的。使用上面的行,您还需要更改 "pop" 视图的方式。
await Navigation.PopModalAsync (true);
注:
这些消息即使在您工作时也会出现在日志中。
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
[0:] Binding: 'DefaultOverlayTopText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.TopText'
[0:] Binding: 'DefaultOverlayBottomText' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.BottomText'
[0:] Binding: 'DefaultOverlayShowFlashButton' property not found on 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay', target property: 'ZXing.Net.Mobile.Forms.ZXingDefaultOverlay.ShowFlashButton'
希望对您有所帮助。-