protected async override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); this.Debug("OnElementPropertyChanged"); if (!HasValidSurface) { return; } if (e.PropertyName == BarcodeScanner.IsEnabledProperty.PropertyName) { this.Debug("Enabled [{0}]", Element.IsEnabled); if (Element.IsEnabled && HasValidSurface) { await Task.Run(() => CameraService.OpenCamera()); } if (!Element.IsEnabled) { ReleaseCamera(); } } if (e.PropertyName == BarcodeScanner.PreviewActiveProperty.PropertyName) { this.Debug("ScannerActive [{0}]", Element.PreviewActive); if (Element.PreviewActive) { await Task.Run(() => CameraService.StartPreview(Control.Holder)); } if (!Element.PreviewActive) { CameraService.HaltPreview(); } } if (e.PropertyName == BarcodeScanner.TorchProperty.PropertyName) { if (!Platform.HasFlashPermission) { this.Debug("Unable to use flashlight: Android Manifest '{0}' permission not granted.", Android.Manifest.Permission.Flashlight); return; } if (!Platform.HasFlash) { this.Debug("Unable to use flashlight: Device's camera does not support flash."); return; } this.Debug("Torch [{0}]", Element.Torch); CameraService.ToggleTorch(Element.Torch); } if (e.PropertyName == BarcodeScanner.BarcodeDecoderProperty.PropertyName) { this.Debug("Decoder state [{0}]", Element.BarcodeDecoder); if (Element.BarcodeDecoder) { CameraService.StartDecoder(); } if (!Element.BarcodeDecoder) { CameraService.StopDecoder(); } } }