如何在另一页上显示条形码扫描结果,而不是在xamarinforms中使用displayalert

时间:2016-07-30 07:55:24

标签: c#-4.0

我想在另一页显示条形码扫描结果..任何人都可以告诉我..我是xamarin的新手 这是我的cs。代码

public class HomePage : ContentPage
{
    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 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
            }
        };
    }
}

0 个答案:

没有答案