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!

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
0 comments No comments
{count} votes

Accepted answer
  1. Alessandro Caliaro 4,181 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