【问题标题】:How to properly set options for ZXingScannerView?如何正确设置 ZXingScannerView 的选项?
【发布时间】:2021-01-16 09:26:49
【问题描述】:

我在 Xamarin Forms 项目中使用 Zxing.Net.Mobile。

我调用 ZXingScannerView 到页面,但扫描仪选项似乎不起作用。我设置了要扫描的特定类型的条形码,但它仍然可以扫描所有焦点。

我在 page.xaml 调用scannerview:

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

然后在 xaml.cs 中定义选项

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

我做错了什么?

【问题讨论】:

  • 您只能绑定到公共属性。 opts 是本地字段,而不是公共属性。尝试在页面构造函数中将opts 显式分配给scanView
  • @Jason,是的,它有帮助。谢谢。
  • @PavelPolushin 嗨,如果您已经解决了这个问题,请记得分享您的解决方案作为答案。然后其他人在遇到相同问题时就会知道如何解决。

标签: android xamarin.forms xamarin.android zxing zxing.net


【解决方案1】:

感谢@Jason。 答案是像这样在页面构造函数中选择 scanView

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 2012-08-25
    • 2015-10-22
    • 1970-01-01
    相关资源
    最近更新 更多