how to display barcode scanner values in another page?

here im using display alert. But instead of display alert i want to show my value in another page.

public HomePage()
{
Button scanBtn = new Button
{
Text = "Scan Barcode",
HorizontalOptions = LayoutOptions.FillAndExpand,
};

        scanBtn.Clicked += async (sender, args) =>
        {
            var scanResult = await Acr.BarCodes.BarCodes.Instance.Read();
            if (!scanResult.Success)
            {
                await Navigation.PushAsync(new Page1());
               // await this.DisplayAlert("Alert ! ", "Sorry ! \n Failed to read the Barcode !", "OK");
            }
            else
            {
                await this.DisplayAlert("Scan Successful !", String.Format("Barcode Format : {0} \n Barcode Value : {1}", scanResult.Format, scanResult.Code), "OK");

                string id = scanResult.Code;
            }
        };

        Content = new StackLayout
        {
            Children = {
                scanBtn
            }
        };
    }

Best Answer

Answers

  • scottscott Member ✭✭

    Hi Sir @AlessandroCaliaro, I am new to xamarin but I have the same problem above. If you can give me sample code about how to use NavigationPage and Push a page on the stack is much appreciated.

    Thank you very much.

  • scottscott Member ✭✭

    Thank you Sir @AlessandroCaliaro, I am new to Xamarin and I tried the code from your link and I got some error. I just want to pass the value of result.text to another page instead of displaying on DisplayAlert. Your help is highly appreciated.

    private async void ButtonScanDefault_Clicked(object sender, EventArgs e)
    {
    scanPage = new ZXingScannerPage();
    scanPage.OnScanResult += (result) =>
    {
    scanPage.IsScanning = false;
    Device.BeginInvokeOnMainThread(() =>
    {
    Navigation.PopModalAsync();
    DisplayAlert("Scanned Barcode", result.Text, "OK");
    });
    };
    await Navigation.PushModalAsync(scanPage);
    }

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Device.BeginInvokeOnMainThread(() =>
    {
        Navigation.PopModalAsync();
        DisplayAlert("Scanned Barcode", result.Text, "OK");
    
        await Navigation.PushAsync(new MyPage(result.Text)); // Something like this...
    });
    
  • scottscott Member ✭✭

    Thank you for the reply Sir @AlessandroCaliaro but I am sad to say that it doesn't work.

    System.InvalidOperationException:PushAsync is not supported globally on Android, please use a NavigationPage.

    But when I use the NavigationPage.PushAsync(new Page(result.Text));

    Error is An object reference is required for the non-static field, method, or property 'NavigationPage.PushAsync(Page)'

    Thank you very much Sir.

Sign In or Register to comment.