void AddPageContent() { this.Title = "Scan Barcode"; zxing = new ZXingScannerView { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; 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(); //}); Device.BeginInvokeOnMainThread(async() => { // Stop analysis until we navigate away so we don't keep reading barcodes zxing.IsAnalyzing = false; //Binding data try { if (!CommonLib.checkconnection()) { RacoonAlertPopup.textmsg = "Check your internet connection."; await App.Current.MainPage.Navigation.PushPopupAsync(new RacoonAlertPopup()); return; } await App.Current.MainPage.Navigation.PushPopupAsync(new LoadPopup()); string postData = "barcode=" + result + "&userId=" + LoginDetails.userId + ""; var response = await CommonLib.BarcodeScanner(CommonLib.ws_MainUrl + "AccountApi/ScanBarcode?" + postData, ""); if (response != null && response.Status != 0) { LoadPopup.CloseAllPopup(); RacoonAlertPopup.textmsg = response.msg; await App.Current.MainPage.Navigation.PushPopupAsync(new RacoonAlertPopup()); await Navigation.PopAsync(); } else { LoadPopup.CloseAllPopup(); RacoonAlertPopup.textmsg = response.msg; await App.Current.MainPage.Navigation.PushPopupAsync(new RacoonAlertPopup()); await Navigation.PopAsync(); } } catch (Exception ex) { LoadPopup.CloseAllPopup(); await App.Current.MainPage.DisplayAlert("", ex.Message, "OK"); } finally { } // Show an alert // Navigate away }); overlay = new ZXingDefaultOverlay { TopText = "Hold your phone up to the barcode", BottomText = "Scanning will happen automatically", ShowFlashButton = zxing.HasTorch, }; overlay.FlashButtonClicked += (sender, e) => { zxing.IsTorchOn = !zxing.IsTorchOn; }; var grid = new Grid { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; grid.Children.Add(zxing); grid.Children.Add(overlay); // The root page of your application Content = grid; }