I have a page with ScannerView as MainPage. When I start the app it can't scan a barcode. I have to set another page as mainpage then navigate to the scanner page, before it can scan a barcode. Or lock and then unlock the phone, then it will start scanning.

App.xaml.cs:

```
MainPage = new NavigationPage(new ScannerPage());

```

ScannerPage.xaml:

```
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MyApp.Pages.ScannerPage"
             xmlns:zxing="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms">
    <ContentPage.Content>
        <Grid>
            <zxing:ZXingScannerView x:Name="ScannerView"
                                    IsScanning="True"
                                    IsAnalyzing="True" />
            <zxing:ZXingDefaultOverlay x:Name="ScannerOverlay"
                                       TopText="Hold your phone up to the QR code"
                                       BottomText="Scanning will happen automatically"
                                       ShowFlashButton="True"/>
        </Grid>
    </ContentPage.Content>
</ContentPage>

```

ScannerPage.xaml.cs:

```
public partial class ScannerPage : ContentPage
{
    public ScannerPage ()
    {
        InitializeComponent ();

        ScannerView.Options = new MobileBarcodeScanningOptions
        {
            PossibleFormats = new List<BarcodeFormat>
            {
                BarcodeFormat.DATA_MATRIX,
            },
            TryHarder = true
        };

        ScannerView.OnScanResult += (result) => Device.BeginInvokeOnMainThread(async () =>
        {
            ScannerView.IsAnalyzing = false;
            await DisplayAlert("Scanned", result.Text, "Ok");
            ScannerView.IsAnalyzing = true;
        });
    }
}

```