【问题标题】:Xamarin forms shared ZXingScannerPage KeyNotFoundExceptionXamarin 表单共享 ZXingScannerPage KeyNotFoundException
【发布时间】:2019-01-09 20:10:06
【问题描述】:

我使用共享代码创建了一个新的 xamarin 项目。

我已经安装了 ZXing.Net.MobileZXing.Net.Mobile.Forms nuget 包。我尝试了很多教程,但是当我调用扫描仪页面时它一直抛出异常。

这是我的代码:

 private void Button_OnClicked(object sender, EventArgs e)
        {
            var scan = new ZXingScannerPage();

            Navigation.PushAsync(scan);

            scan.OnScanResult += Scan_OnScanResult;
        }

        private void Scan_OnScanResult(ZXing.Result result)
        {
            if (result != null)
            {
                Device.BeginInvokeOnMainThread(
                                               async () =>
                                                   {
                                                       await Navigation.PopAsync(true);
                                                       MyCode.Text = result.Text;
                                                   });
            }
        }

知道如何让它在新的 xamarin 项目上运行吗? 我已经检查了 android manifest 中的相机。

【问题讨论】:

    标签: c# xamarin qr-code zxing


    【解决方案1】:

    你能试试这个代码,让我知道它是否有效吗?根据该异常消息,很难说可能是什么问题。

            try
            {
                var scanPage = new ZXingScannerPage();
                scanPage.IsScanning = true;
    
                scanPage.OnScanResult += (result) =>
                {
                // Stop scanning
                scanPage.IsScanning = false;
    
                // Pop the page and show the result
                Device.BeginInvokeOnMainThread(async () =>
                    {
                        await Navigation.PopAsync(true);
    
                        await DisplayAlert("Scanned Code", result.Text, "OK");
                    });
                };
    
                Navigation.PushAsync(scanPage);
            }
            catch
            {
                // handle exception
            }
    

    【讨论】:

    • 谢谢,但最后我找到了解决方案。问题在于 Xamarin Live 播放器。我不知道为什么,但如果我通过 USB 插入它可以工作,但如果我使用实时播放器,它会抛出错误。我不明白。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多