WPF 绑定到已安装的打印机列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13488910/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:18:55  来源:igfitidea点击:

WPF Bind to the list of installed printers

wpflistxamlprintingbind

提问by Mike de Klerk

How to bind to the list of System.Drawing.Printing.PrinterSettings.InstalledPrinters, which is a static StringCollection, in WPF XAML. For example, to use it in a ComboBox, so a user can select the printer to use.

如何在 WPF XAML 中绑定到 System.Drawing.Printing.PrinterSettings.InstalledPrinters 列表,它是一个静态 StringCollection。例如,在 ComboBox 中使用它,以便用户可以选择要使用的打印机。

回答by Mike de Klerk

Add the namespace for System.Drawing.Print to your XAML code:

将 System.Drawing.Print 的命名空间添加到您的 XAML 代码中:

xmlns:Printing="clr-namespace:System.Drawing.Printing;assembly=System.Drawing"

Then add the combobox to show the list of printers installed on the system:

然后添加组合框以显示系统上安装的打印机列表:

<ComboBox Name="cmbPrinterSelection" Width="300" ItemsSource="{x:Static Printing:PrinterSettings.InstalledPrinters}" SelectionChanged="cmbPrinterSelection_SelectionChanged" />

Hopefully this will save someone some time.

希望这会为某人节省一些时间。