How to properly set options for ZXingScannerView?

Viewed 1324

I use Zxing.Net.Mobile in my Xamarin Forms project.

I call ZXingScannerView to the page but scanner options seems to be not working. I set specific type of barcode to scan but it sill scans everything in focus.

I call scannerview at page.xaml:

 <zxing:ZXingScannerView x:Name="scanView"
                                        Grid.Row="0"
                                        Options="{Binding opts}"
                                        IsScanning="True"
                                        WidthRequest="300"
                                        HeightRequest="600"
                                        VerticalOptions="CenterAndExpand"
                                        HorizontalOptions="CenterAndExpand"/>

And then define options at xaml.cs

public static readonly ZXing.Mobile.MobileBarcodeScanningOptions opts = new ZXing.Mobile.MobileBarcodeScanningOptions
        {
            PossibleFormats = new List<ZXing.BarcodeFormat> { ZXing.BarcodeFormat.AZTEC },
            TryHarder=true
        };

What am I doing wrong?

1 Answers

Thanks to @Jason. The answer is to assing opts to scanView in the page constructor like this

public ScanPage()
        {
            InitializeComponent();
            scanView.Options = opts;
        }
Related