简体   繁体   中英

WPF - Print contents of ListView?

I've created my own usercontrol that makes use of a ListView to display an arbitratry list of items. On each Page within my project the ListView's columns in XAML and then bound to my object.

Now what I'm trying to do is to write a single Print method within my control that will print out the entire contents of the ListView.

I read a similar question where the answer was stated that I should convert my ItemsSource into a Table. If, indeed, that is the way to accomplish this task, can someone be so kind as to walk me through that process for an arbitrary object?

Thanks,
Sonny

由于ListViewVisual派生,也许您可​​以使用PrintVisual()方法来打印列表视图本身:

new PrintDialog().PrintVisual(yourListView, "Print Job Description");

Well... I finally (sort of) solved the issue.

I've iterated through the GridViewColumns within my ListView and for each column I also iterate through the ItemSource of the ListView and use Reflection to get the DisplayMemberBinding.Path.Path which I can then use to get the property's value.

The DisplayMemberBinding also has information for all my converters, so I'm good to go.

It's slow (about 10 seconds for 400 lines in a ListView), but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM