Zxing.net.mobile: UWP Unable to update UI after scanning

Created on 6 May 2016  路  7Comments  路  Source: Redth/ZXing.Net.Mobile

After scanning a QR Code, I perform a long running task, and update the UI to notify the user that the task is running. This does not work after performing a scan. Below is the code I am using to try and update the UI.

public sealed partial class MainPage : Page
{

    MobileBarcodeScanner scanner;

    public MainPage()
    {
        this.InitializeComponent();
        scanner = new MobileBarcodeScanner(Dispatcher);
    }

    public void NotifyUser(bool runningLongTask)
    {
        // Update Some UI stuff here
    }

    private async void StartScan(object sender, RoutedEventArgs e)
    {
        await scanner.Scan().ContinueWith(async t =>
        {
            if (t.Result != null && !string.IsNullOrEmpty(t.Result.Text))
            {
                // Update UI Components.  Does not work
                NotifyUser(true);

                // Simulate a long running task
                await Task.Delay(10000);

                // Update UI Components.  Does not work again.
                NotifyUser(false);

            }
        });
    }
}

All 7 comments

Looks like we have the same issue: #319

I have forked the project and updated the Windows Universal sample to help illustrate this issue as well.

I downloaded the 2.1 beta NuGet package in VS2015 and it goes the same way.

This sample uses ZXing 0.14.1 and seems to be working:
https://github.com/naotaco/UwpQrCodeReaderSample

Maybe some code for the scanner could be taken from it.

Ok my very similar problem was fixed.
Anyone having this problem might look into the solution in #320 .
adding NavigationCacheMode="Enabled" to the Page (in Xamarin PCL add this to the UWP Project MainPage.xaml not in any xaml files in the PCL folder as it does not exist in Xamarin)

If this solves it, it might be a good idea to include that into the Readme.
And thanks again to Strifex for this solution.

Added this to the sample and README in 4b45f9079366fc62ff6aeec12fbbe02db597b53b

I ran into the exact same issue on Android. Is there a fix or workaround?

Was this page helpful?
0 / 5 - 0 ratings