0

I have an issue in a WPF Application, I want to get a screenshot for a ListBox.

The list contain more than 100 items, some of items are hidden by scrolling down. Only get the items which are not hidden in scroll when take a screenshot.

Could you please help me out in getting all the items of list for one screenshot?

  • Can you clarify what you mean by screenshot? And "Only get the items which are not hidden in scroll when take a screenshot." Do you mean only non-hidden items are being selected or do you only want to get non-hidden items? – CalebB Apr 21 '15 at 03:36
  • I want save a view which is contains a ListBox to image, only show the non-didden items on the image when I get the screenshot, I want get all the items of ListBox on the screenshot at one time. – user3286132 Apr 21 '15 at 04:48

1 Answers1

1

If the ListView is to be visible while rendering it to an image you can put it (preferably temporarily) inside a ScrollViewer, which will give it an infinite layout space, so the ListViewItems aren't virtualized away from the render, then you can use RenderTargetBitmap on the ListView.

If you don't have to show the ListView you can render it off-screen as this answer shows, like so:

var listView = new ListView{ ItemsSource = ... etc }
listView.Measure(new Size(10000, 20000));
listView.Arrange(new Rect(new Size(10000, 20000)));

RenderTargetBitmap bmp = new RenderTargetBitmap(listView.ActualWidth, listView.ActualHeight, 96, 96, PixelFormats.Pbgra32);

bmp.Render(control);

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bmp));
encoder.Save(somewhere);
Community
  • 1
  • 1
Sten Petrov
  • 10,943
  • 1
  • 41
  • 61