Inheritance: Xamarin.Forms.Grid
        public ZXingScannerPage (MobileBarcodeScanningOptions options = null, View customOverlay = null) : base ()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Options = options
            };

            zxing.OnScanResult += (result) => {
                var eh = this.OnScanResult;
                if (eh != null)
                    eh(result);
                    //Device.BeginInvokeOnMainThread (() => eh (result));
            };

            if (customOverlay == null) {
                defaultOverlay = new ZXingDefaultOverlay {
                    TopText = "Hold your phone up to the barcode",
                    BottomText = "Scanning will happen automatically",
                    ShowFlashButton = zxing.HasTorch,
                };
                defaultOverlay.FlashButtonClicked += (sender, e) => {
                    zxing.IsTorchOn = !zxing.IsTorchOn;
                };
                Overlay = defaultOverlay;
            } else {
                Overlay = customOverlay;
            }

            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;
        }
        public ZXingScannerPage (MobileBarcodeScanningOptions options = null, View customOverlay = null) : base ()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Options = options,
                AutomationId = "zxingScannerView"
            };

            zxing.SetBinding( ZXingScannerView.IsTorchOnProperty, new Binding( nameof( IsTorchOn ) ) );
            zxing.SetBinding( ZXingScannerView.IsAnalyzingProperty, new Binding( nameof( IsAnalyzing ) ) );
            zxing.SetBinding( ZXingScannerView.IsScanningProperty, new Binding( nameof( IsScanning ) ) );
            zxing.SetBinding( ZXingScannerView.HasTorchProperty, new Binding( nameof( HasTorch ) ) );
            zxing.SetBinding( ZXingScannerView.ResultProperty, new Binding( nameof( Result ) ) );

            zxing.OnScanResult += (result) => {
                this.OnScanResult?.Invoke( result );
                //Device.BeginInvokeOnMainThread (() => eh (result));
            };

            if (customOverlay == null) {
                defaultOverlay = new ZXingDefaultOverlay () { AutomationId = "zxingDefaultOverlay" };

                defaultOverlay.SetBinding( ZXingDefaultOverlay.TopTextProperty, new Binding( nameof( DefaultOverlayTopText ) ) );
                defaultOverlay.SetBinding( ZXingDefaultOverlay.BottomTextProperty, new Binding( nameof( DefaultOverlayBottomText ) ) );
                defaultOverlay.SetBinding( ZXingDefaultOverlay.ShowFlashButtonProperty, new Binding( nameof( DefaultOverlayShowFlashButton ) ) );

                DefaultOverlayTopText = "Hold your phone up to the barcode";
                DefaultOverlayBottomText = "Scanning will happen automatically";
                DefaultOverlayShowFlashButton = HasTorch;

                defaultOverlay.FlashButtonClicked += (sender, e) => {
                    zxing.IsTorchOn = !zxing.IsTorchOn;
                };

                Overlay = defaultOverlay;
            } else {
                Overlay = customOverlay;
            }

            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;
        }
Example #3
0
        public CustomScanPage () : base ()
        {
            zxing = new ZXingScannerView
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                AutomationId = "zxingScannerView",
            };
            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 ();
                });

            overlay = new ZXingDefaultOverlay
            {
                TopText = "Hold your phone up to the barcode",
                BottomText = "Scanning will happen automatically",
                ShowFlashButton = zxing.HasTorch,
                AutomationId = "zxingDefaultOverlay",
            };
            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;
        }