3

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?

Pavel Polushin
  • 351
  • 2
  • 5
  • 16
  • 2
    you can only bind to public properties. `opts` is a local field, not a public property. Try explicitly assigning `opts` to `scanView` in the page constructor. – Jason Jan 16 '21 at 09:32
  • 1
    @Jason,Yes it helped. Thank you. – Pavel Polushin Jan 16 '21 at 14:32
  • 1
    @PavelPolushin Hi, if you have solved that, remember to share your solution as an answer. Then other people will know how to solve that when they have the same problems. – Junior Jiang Jan 18 '21 at 03:14

1 Answers1

1

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

public ScanPage()
        {
            InitializeComponent();
            scanView.Options = opts;
        }
Pavel Polushin
  • 351
  • 2
  • 5
  • 16