C# 如何在xamarin表单中打印生成的条形码ZXING
我设法用ZXING库生成了一个条形码,现在我想打印生成的条形码,因为它来自ZXingBarcodeImageView,大小相同,我该怎么做C# 如何在xamarin表单中打印生成的条形码ZXING,c#,xamarin,xamarin.forms,zxing,C#,Xamarin,Xamarin.forms,Zxing,我设法用ZXING库生成了一个条形码,现在我想打印生成的条形码,因为它来自ZXingBarcodeImageView,大小相同,我该怎么做 private async Task<Item> getItem() { HttpResponseMessage _response = await _client.GetAsync(url + txt_Barcode.Text); if (_response.IsSuccessStatusCode)
private async Task<Item> getItem()
{
HttpResponseMessage _response = await _client.GetAsync(url + txt_Barcode.Text);
if (_response.IsSuccessStatusCode)
{
string itemDetailes = await _response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<Item>(itemDetailes);
}
return new Item();
}
private async void Btn_GetInfo(object sender, EventArgs e)
{
var selected_item = await getItem();
// Item_barcode.Text = selected_item.Value;
Item_Description.Text = selected_item.Description;
Item_name.Text = selected_item.Name;
Item_price.Text = selected_item.Price.ToString();
item_barcode.BarcodeValue = selected_item.Value;
}
private异步任务getItem()
{
HttpResponseMessage\u response=wait\u client.GetAsync(url+txt\u Barcode.Text);
如果(_response.issucessStatusCode)
{
string itemDetails=wait_response.Content.ReadAsStringAsync();
返回JsonConvert.DeserializeObject(ItemDetails);
}
返回新项目();
}
私有异步void Btn_GetInfo(对象发送方,事件参数e)
{
var selected_item=wait getItem();
//Item\u barcode.Text=所选的\u Item.Value;
Item_Description.Text=所选的_Item.Description;
Item_name.Text=所选的_Item.name;
Item_price.Text=所选的_Item.price.ToString();
item_barcode.BarcodeValue=所选的_item.Value;
}
xaml代码
最好也是最简单的方法是在webview中显示条形码。 这是一个你可以使用的图书馆 您可以在资源文件夹中复制脚本。创建html文件并导入脚本 现在从webview中的xamarin端Evalute javascript开始,您可以将条形码数据发送到webview 这是你可以做到的。 注意:您不需要进行任何自定义渲染 使用此功能,您可以删除zxing并缩小应用程序大小您的意思是“打印”到物理打印机吗?
<!--<Image HeightRequest="300" WidthRequest="300" Margin="1" x:Name="img_barcode"></Image>-->
<zxing:ZXingBarcodeImageView x:Name="item_barcode" HeightRequest="20" WidthRequest="100" BarcodeFormat="CODE_39" BarcodeValue="Place Barcode" >
<zxing:ZXingBarcodeImageView.BarcodeOptions>
<zxingcomon:EncodingOptions Height="80" Width="1000"></zxingcomon:EncodingOptions>
</zxing:ZXingBarcodeImageView.BarcodeOptions>
</zxing:ZXingBarcodeImageView>
<StackLayout Orientation="Horizontal" Spacing="20" >
<Label TextColor="Black" x:Name="Item_Description"></Label>
<Label TextColor="Black" x:Name="Item_price"></Label>
</StackLayout>
<StackLayout x:Name="SLPrint" BackgroundColor="GhostWhite" VerticalOptions="FillAndExpand">
<Button Text="print" BackgroundColor="Black" TextColor="White"></Button>
</StackLayout>
</StackLayout>
</StackLayout>