在不支持的目标框架上显示打印对话框的行为

Curtis Chau
Curtis Chau
更新: 2026年7月6日

ShowPrintDialog 和 ShowPrintDialogAsync 需要一个UI组件来显示打印对话框。 它们在缺乏UI功能的目标框架上不受支持,例如纯.NET Core或.NET Standard版本。

在不支持的TargetFramework上调用任一方法可能会引发类似如下的错误:

System.AggregateException: 'One or more errors occurred.
(Please try Print/PrintAsync since ShowPrintDialog/ShowPrintDialogAsync in NET Core or NET Standard,
it required UI component so please set more specific OS TargetFrameworks
e.g. net462; net472; net7.0-windows; net7.0-macos; net7.0-maccatalyst; net7.0-android)'
Text

对话框方法需要一个UI组件,而普通的.NET Core或.NET Standard目标中不可用。

解决方案

针对具有UI功能的框架以显示对话框

要获取实际的打印对话框,请针对包含UI支持的特定操作系统目标进行构建:

<TargetFrameworks>net462;net472;net7.0-windows;net7.0-macos;net7.0-maccatalyst;net7.0-android</TargetFrameworks>
XML

使用其中一个框架后,ShowPrintDialog 和 ShowPrintDialogAsync 如预期地显示对话框。

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

阅读更多

准备开始了吗?

NuGet 下载量 52,427版本:2026.11刚刚发布