0

I am trying to display a barcode in my app using binding in my xaml. My question is how can I convert the barcode to be used in the xaml Image source. I have tried using a byte property but I get this compile error : "Cannot implicitly convert Zxing barcode image view to 'byte'". Any guidance on how to achieve this will be appreciate, thanks.

Cards.cs

 public class Cards
    {
        public int CustomerID { get; set; }
        public int DiscountLevelID { get; set; }
        public string DiscountLevel { get; set; }
        public double DiscountLevelAmount { get; set; }
        public bool StoreCustomerGiftCard { get; set; }
        public bool StoreCustomerLoyalty { get; set; }
        public int LoyaltyLevelID { get; set; }
        public string LoyaltyLevel { get; set; }
        public double LoyaltyLevelRatio { get; set; }
        public double Balance { get; set; }
        public int StoreNumber { get; set; }
        public string CardNumber { get; set; }
        public bool IsError { get; set; }
        public object ErrorMessage { get; set; }
        public string CompanyName { get; set; }
        public string CustomerLogo { get; set; }
        public byte BarCode { get; set; }

    }

Cards.xaml.cs

ZXingBarcodeImageView barcode;

 barcode = new ZXingBarcodeImageView { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand };
                        barcode.BarcodeFormat = ZXing.BarcodeFormat.QR_CODE;
                        barcode.BarcodeOptions.Width = 300;
                        barcode.BarcodeOptions.Height = 300;
                        barcode.BarcodeOptions.Margin = 10;
                        barcode.BarcodeValue = i.CardNumber;

                        i.BarCode = barcode;

Cards.xaml

<Image Source="{Binding BarCode}" />
Janine Alexander
  • 151
  • 4
  • 22

1 Answers1

4

ZXingBarcodeImageView inherits directly from Image, so you use it as an alternative to Image, not as a source for Image

xmlns:zx="clr-namespace:ZXing.Net.Mobile.Forms;assembly=ZXing.Net.Mobile.Forms"
xmlns:zxcm="clr-namespace:ZXing.Common;assembly=zxing.portable"

<zx:ZXingBarcodeImageView
    BarcodeFormat="QR_CODE"
    BarcodeValue="{Binding CardNumber}"
    HorizontalOptions="FillAndExpand"
    VerticalOptions="FillAndExpand">
    <zx:ZXingBarcodeImageView.BarcodeOptions>
      <zxcm:EncodingOptions Width="300" Height="300" />
    </zx:ZXingBarcodeImageView.BarcodeOptions>
</zx:ZXingBarcodeImageView>
Jason
  • 86,222
  • 15
  • 131
  • 146