0

我正在尝试使用我的 xaml 中的绑定在我的应用程序中显示条形码。我的问题是如何转换要在 xaml 图像源中使用的条形码。我曾尝试使用字节属性,但出现此编译错误:“无法将 Zxing 条形码图像视图隐式转换为 'byte'”。任何有关如何实现这一目标的指导将不胜感激,谢谢。

卡片.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; }

    }

卡片.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;

卡片.xaml

<Image Source="{Binding BarCode}" />
4

1 回答 1

4

ZXingBarcodeImageView直接继承自Image,因此您可以将其用作 的替代品Image,而不是作为 的来源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>
于 2018-01-20T17:57:29.103 回答