Xamarin.Forms - Navigation.PushAsync "Only the original thread that created a view hierarchy can touch its views"

Ganesh Gebhard 366 Reputation points
2021-08-19T13:53:24.99+00:00

Hey!

I have a page with a barcode scanner in which another page is opened when a scan is completed. I use Navigation.PushAsync, which works everywhere in the app, but somehow it doesn't work here and throws the exception "Only the original thread that created a view hierarchy can touch its views". I have no idea how to fix this, so hopefully someone is able to help.

The interface:
124738-image.png

Getting the scanned result and redirecting to the page (simplified):
124745-image.png

Opening the page (simplified):
124753-image.png

The error occurs at line 127. I hope someone can help!

Developer technologies .NET Xamarin
Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. Alessandro Caliaro 4,196 Reputation points
    2021-08-19T14:07:26.083+00:00

    Try

    Device.BeginInvokeOnMainThread (async() => {
    await Navigation.PushAsync...
    });

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.