1

I'm trying to use ZXing.Net.Maui scanner in an empty .Net Maui app.

I seems like it doesn't work if the app doesn't use shell.

Here is my app class code:

The scanner works if the app is initialized using this code:

namespace MauiApp1;

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new AppShell();
    }
}

However if the app is initialized using this code, it doesn't work. The camera view is just black and doesn't shod the camera feed.

namespace MauiApp1;

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new NavigationPage(new MainPage());
    }
}

In both cases I'm creating the scanner by following the different steps in the documentation:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:zxing="clr-namespace:ZXing.Net.Maui.Controls;assembly=ZXing.Net.MAUI"
             x:Class="MauiApp1.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <zxing:CameraBarcodeReaderView x:Name="cameraBarcodeReaderView" />
            
        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

C#

using ZXing.Net.Maui;
namespace MauiApp1;

public partial class MainPage : ContentPage
{
    int count = 0;

    public MainPage()
    {
        InitializeComponent();
        cameraBarcodeReaderView.Options = new BarcodeReaderOptions
        {
            Formats = BarcodeFormats.OneDimensional,
            AutoRotate = true,
            Multiple = true
        };
    }
}

What am I doing wrong? My app doesn't use Shell. So I'm unable to use the scanner.

halfer
  • 19,824
  • 17
  • 99
  • 186
Thomas Carlton
  • 5,344
  • 10
  • 63
  • 126

1 Answers1

0

I can replicate the issue you descripted above and I notice that there is an open issue you raised about this problem: https://github.com/Redth/ZXing.Net.Maui/issues/109.

As an alternative workaround, if you don't want the app use shell when initializing the app, you can use the code below:

namespace MauiApp1;

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new MainPage();
    }
}
Alexandar May - MSFT
  • 6,536
  • 1
  • 8
  • 15