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.