private void buttonScanCustom_Click(object sender, RoutedEventArgs e) { //Get our UIElement from the MainPage.xaml (this) file // to use as our custom overlay if (customOverlayElement == null) { customOverlayElement = this.customOverlay.Children[0]; this.customOverlay.Children.RemoveAt(0); } //Wireup our buttons from the custom overlay this.buttonCancel.Click += (s, e2) => { scanner.StopScanning(); }; this.buttonFlash.Click += (s, e2) => { scanner.ToggleTorch(); }; //Set our custom overlay and enable it scanner.CustomOverlay = customOverlayElement; scanner.UseCustomOverlay = true; //Start Scanning scanner.StartScanning((result) => { //Scanning finished callback HandleScanResult(result); }); }
public override void ViewDidLoad() { //Create a new instance of our scanner scanner = new ZxingScanner(); //Setup our button buttonDefaultScan = new UIButton(UIButtonType.RoundedRect); buttonDefaultScan.Frame = new RectangleF(20, 80, 280, 40); buttonDefaultScan.SetTitle("Scan with Default View", UIControlState.Normal); buttonDefaultScan.TouchUpInside += (sender, e) => { //Tell our scanner to use the default overlay scanner.UseCustomOverlay = false; //We can customize the top and bottom text of the default overlay scanner.TopText = "Hold camera up to barcode to scan"; scanner.BottomText = "Barcode will automatically scan"; //Start scanning scanner.StartScanning((result) => { //Our scanning finished callback HandleScanResult(result); }); }; buttonCustomScan = new UIButton(UIButtonType.RoundedRect); buttonCustomScan.Frame = new RectangleF(20, 20, 280, 40); buttonCustomScan.SetTitle("Scan with Custom View", UIControlState.Normal); buttonCustomScan.TouchUpInside += (sender, e) => { //Create an instance of our custom overlay customOverlay = new CustomOverlayView(); //Wireup the buttons from our custom overlay customOverlay.ButtonTorch.TouchUpInside += delegate { scanner.ToggleTorch(); }; customOverlay.ButtonCancel.TouchUpInside += delegate { scanner.StopScanning(); }; //Tell our scanner to use our custom overlay scanner.UseCustomOverlay = true; scanner.CustomOverlay = customOverlay; scanner.StartScanning((result) => { //Our scanning finished callback HandleScanResult(result); }); }; this.View.AddSubview(buttonDefaultScan); this.View.AddSubview(buttonCustomScan); }