首页 > 解决方案 > ZXing 二维码扫描器 Xamarin

问题描述

我试图实现包 ZXing.Net.Mobile.Forms

这是我的 XAML:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
         Title="{Binding Title}">

<ContentPage.Content>
    <StackLayout>
        <Label x:Name="scanResultText" />
        <zxing:ZXingScannerView 
            OnScanResult="ScanViewOnScanResult"/>
    </StackLayout>
</ContentPage.Content>

这是我的 xaml.cs :

public partial class QRCodePage : ContentPage
{

    public QRCodePage()
    {
        InitializeComponent();

        BindingContext = new QRCodeViewModel();
    }

    public void ScanViewOnScanResult(Result result)
    {
        Device.BeginInvokeOnMainThread(async () =>
        {
            scanResultText.Text = result.Text;
        });
    }
}

在我的设备上,我看到了片段,但似乎没有扫描

标签: xamarinqr-codezxing

解决方案


尝试将以下代码 ( IsScanning="True") 添加到您的 xaml:

<StackLayout>
    <Label x:Name="scanResultText" />
    <zxing:ZXingScannerView IsScanning="True"
        OnScanResult="ScanViewOnScanResult"/>
</StackLayout>

推荐阅读