我正在尝试使用我的xaml中的绑定在我的应用中显示条形码。我的问题是如何转换要在xaml Image源中使用的条形码。我尝试过使用byte属性,但是我得到了这个编译错误:"无法将Zxing条形码图像视图隐式转换为' byte'" 。任何有关如何实现这一目标的指导都将不胜感激,谢谢。
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}" />
答案 0 :(得分:3)
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>