从Xamarin.Forms应用程序打印 [英] Printing from a Xamarin.Forms app

查看:407
本文介绍了从Xamarin.Forms应用程序打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Xamarin的新手,目前正在使用Xamarin.Forms进行示例或概念验证"应用程序.

I'm all new to Xamarin and I'm currently working on a sample or a "prove of concept" app using Xamarin.Forms.

尽管我现在还不确定要打印什么(屏幕,标签内容,文件等),但我应该从该应用程序执行打印任务.

I'm supposed to perform a print task from this app though I'm not at this point sure what to print yet (the screen, content of a label, a file etc.).

无论哪种方式,从Xamarin.Forms应用程序打印的最简单方法是什么? (当前目标主要是Android 4.4 +).

Either way, what is the easiest way to print from a Xamarin.Forms app? (current target is primarily Android 4.4+).

我希望这不会太复杂:)

I hope this isn't too complicated :)

好吧,让我更新一下这篇文章,因为原始文本可能会有些野心勃勃/含糊不清.

Ok let me just update this post as the original text might be a bit ambitious/vague.

我有一个Xamarin.Forms项目(+一个Android部分),并且在该项目的XF部分中有一些HTML,需要进入WebView并打印它. 据我了解,WebView的工作必须在项目的Android部分完成,因为事实上这是要处理打印的地方. 我希望可以通过代码完成此操作,因为我真的不需要显示WebView,只需打印其内容即可. 该项目的Android部分只有MainActivity,没有布局或XAML文件. 我不知道在何处添加WebView或如何访问它(除了DependecyService似乎在这里是个时髦的词),所以我有点卡在这里.

I have a Xamarin.Forms project (+ an Android part) and I have some HTML available in the XF part of the project that I need to get into a WebView and print it. From what I understand, the thing with the WebView has to be done on the Android part of the project due to the fact that this is where the printing will be handled. I was hoping this could be done from code since I don't really need to display the WebView, just print it's content. The Android part of the project has only the MainActivity and no layouts or XAML files. I don't know where to add the WebView or how to access it (other than DependecyService seems to be a buzz word here) so I'm kinda stuck here.

我认为对于Xamarin经验比我多一些的人来说,这项任务应该是微不足道的.

I'm thinking that this task should be rather trivial to someone with a little more Xamarin experience than me.

推荐答案

XF支持的每个平台都有其自己的打印机制. XF不提供任何跨平台打印的抽象.您将需要为每一层编写打印逻辑,并使用 DependencyService (或其他一些DI引擎).

Every platform XF supports has it's own mechanism for printing. XF does not provide any abstractions for printing in a cross-platform manner. You will need to write printing logic for each layer and expose it to XF using DependencyService (or some other DI engine).

这篇关于从Xamarin.Forms应用程序打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆