如何使用NetBarcode库显示条形码? [英] How do I use the NetBarcode library to display an Barcode?
本文介绍了如何使用NetBarcode库显示条形码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我第一次使用图书馆。因此,我问了一个关于图书馆的问题: link
是否将条形码添加到我的标签? 在网站上,标签上写着:var barcode = new Barcode ("543534", Type.Code128, true);
但是,当我尝试为标签赋值时,它不起作用。那么,如何使用此库将条形码添加到标签?
因为我在这里不能做很多事情:
如果我想在标签上获得条形码?
推荐答案
简单的方法是定义ValueConverter
public class StringToBarcodeConverter : IValueConverter
{
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string s)
{
var bc = new NetBarcode.Barcode(s, true);
return bc.GetByteArray();
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
并在XAML中使用它。
<Image Source="{Binding Barcode,
Converter={StaticResource StringToBarcodeConverter},
Mode=OneWay}" />
这篇关于如何使用NetBarcode库显示条形码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文