2
我想知道什么是打印ListBox的值最简单的方法。我试图使用FlowDocumentReader但没有成功。Wpf如何打印ListBox
我想知道什么是打印ListBox的值最简单的方法。我试图使用FlowDocumentReader但没有成功。Wpf如何打印ListBox
如果要打印的可视元素,可以使用
PrintDialog printDlg = new PrintDialog();
printDlg.PrintVisual(ListBox1, "Listbox Printing.");
它可用于打印任何视觉对象(任何控制,容器,窗口或用户控制)
如果正在寻找打印的项目才可以使用的FlowDocument
FlowDocument fd = new FlowDocument();
foreach (object item in items)
{
fd.Blocks.Add(new Paragraph(new Run(item.ToString())));
}
fd.Print();
或
PrintDialog pd = new PrintDialog();
pd.PrintDocument(fd);
感谢您的回答biju它是真正的信息,第二种选择正是我正在寻找。但是,现在我从我的所有项目中获得“System.Xml.XmlElement”。我认为这是因为调用对象的ToString()方法,但如何克服它?我的StackPanel里面有XmlDataProvider和ListBox。而ListBox的ItemsSource来自XmlDataProvider。 – GC87 2010-12-24 08:53:20