Storing QR code value to use in API call

CB1216 86 Reputation points
2021-05-05T11:32:02.37+00:00

Hello

I have built a QR/Barcode scanning App in Xamarin Forms. It has two pages, when a QR code is scanned on the first one it navigates to the second page, on this page the user can scan a Barcode and a call out will be made to API to retrieve information about the Barcode. Right now I have hard coded the header in. I know that I can store the header value in a QR code. My question is, is there a way to use the value collected in the first page from the QR code and have that has the header for the API call on the second page.

Frist Page - Scans a QR code and stores that value

Navigate to Second Page

Second Page - Scan a Barcode and using the QR code value as a head, make a call to API.

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. JarvanZhang 23,951 Reputation points
    2021-05-05T12:38:38.67+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    My question is, is there a way to use the value collected in the first page from the QR code and have that has the header for the API call on the second page.

    You could pass the value as a parameter when navigating to the second page.

       public partial class FirstPage : ContentPage  
       {  
           public FirstPage()  
           {  
               InitializeComponent();  
           }  
         
           void functionMethod()  
           {  
               Navigation.PushAsync(new SecondPage(theValue));  
           }  
       }  
         
       public partial class SecondPage : ContentPage  
       {  
           string theResult;  
           public SecondPage(string result)  
           {  
               InitializeComponent();  
         
               theResult = result; //perform the work with the result in the page  
           }  
       }  
    

    Or save the value to the dictionary in the first and retrive it in the second page.

       public partial class FirstPage : ContentPage  
       {  
           public FirstPage()  
           {  
               InitializeComponent();  
           }  
         
           void functionMethod()  
           {  
               Application.Current.Properties["Result"] = theCodeValue;  
               Navigation.PushAsync(new SecondPage());  
           }  
       }  
         
       public partial class SecondPage : ContentPage  
       {  
           string theResult;  
           public SecondPage()  
           {  
               InitializeComponent();  
         
               theResult = Application.Current.Properties["Result"] as string; ; //perform the work with the result in the page  
           }  
       }  
    

    Check the doc: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/application-class#properties-dictionary

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful