我在我的PCL中以Xamarin Form使用Zxing条形码扫描仪。问题是手电筒开/关选项未在UI上显示。这对我来说非常重要,可以为用户提供此选项。
zxing = new ZXingScannerView
{
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
HeightRequest = 400,
AutomationId = "zxingScannerView",
IsTorchOn = true,
};
string _BarCode = "";
int _CountItems = 0;
int _scannedItem = 0;
zxing.OnScanResult += (result) =>
Device.BeginInvokeOnMainThread(async () =>
{
// doing something that i want with scan result
});
overlay = new ZXingDefaultOverlay
{
ShowFlashButton = true,
AutomationId = "zxingDefaultOverlay",
};
overlay.HeightRequest = 2;
overlay.BindingContext = this;
overlay.FlashButtonClicked += (sender, e) =>
{
zxing.IsTorchOn = !zxing.IsTorchOn;
};
在Assambly信息中,我已经添加了这行代码
[assembly: UsesPermission(Android.Manifest.Permission.Flashlight)]
你能否告诉我在我的代码中犯了什么错误。感谢您提出意见和建议
答案 0 :(得分:0)
在扫描按钮中...
var overlay = new ZXingDefaultOverlay
{
ShowFlashButton = true,
TopText = "Please scan the barcode...",
BottomText = string.Empty
};
overlay.BindingContext = overlay;
var scan = new ZXingScannerPage(null, overlay);
await Navigation.PushAsync(scan);
overlay.FlashButtonClicked += (s, ed) =>
{
scan.ToggleTorch();
};
scan.OnScanResult += (result) =>
{
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
var _scanResult = result.Text;
});
};