SL 4 - forced redrawing of the visual tree

Our application has several objects on canvas; the canvas is contained in the scroll viewer. We also have a slider and some buttons, always located at the top of the window.
I'm trying to print an application by capturing a bitmap of the application, but without any โ€œdecorationsโ€ - a slider, buttons or scroll bars.

_scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; _scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden; var s = xSlider; s.Visibility = Visibility.Collapsed; var b = xPlusButton; b.Visibility = Visibility.Collapsed; b = xMinusButton; b.Visibility = Visibility.Collapsed; b = xButton; b.Visibility = Visibility.Collapsed; 

The slider and buttons are hidden, as expected, but the scrollbar is not.
I suspect that the application should redraw the layout to hide the scroll bars. Is there any way to do this? This is complicated by the fact that the print operation in SL 4 must be initiated by a user interface gesture; there is no way (AFAIK) to initiate programmatically, so this redrawing should occur in one of the PrintDocument event handlers.

Thanks for any suggestions ....

+7
silverlight
source share
2 answers

Try the following,

 canvas.InvalidateMeasure(); canvas.InvalidateArrange(); 

Alternatively, you can use WritableBitmap to capture the image at runtime and send the image to print the document, if in case the print document ignores the rendering transformation.

Also, if you use WritableBitmap to capture an element, then you should give RenderTransform as the second argument. Can you post your screen capture code?

+7
source share

In addition to the InvalidateMeasure and InvalidateArrange methods proposed by Akash, you can try the UpdateLayout method.

The two invalidation methods will mark a control measure or order, as they must be executed again, but will not necessarily do so immediately. UpdateLayout will force it to immediately execute some updates.

This is a bit of a black box, so you might need to cancel and then call UpdateLayout. Sometimes you may just need to call UpdateLayout.

+2
source share

All Articles