Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SL 4 -- Force redraw of visual tree

Our application has a number of objects on a canvas; the canvas is contained in a scroll viewer. We also have a slider control and some buttons, always centered at the top of the window.
I am trying to print the application by capturing a bitmap of the app, but without any 'decorations' -- 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 scrollbars are not.
I suspect the application needs to redraw the layout in order to hide the scrollbars. Is there a way to make that happen? This is made more complicated by the fact that the print operation in SL 4 must be initiated by a UI gesture; there is no way (AFAIK) to initiate programatically, so this redraw must happen in one of the PrintDocument event handlers.

Thanks for any suggestions....

like image 625
Number8 Avatar asked Aug 31 '10 11:08

Number8


2 Answers

Try following,

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

You can alternatively use WritableBitmap to capture runtime image and send image to print document if in case print document is ignoring render transform.

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

like image 104
Akash Kava Avatar answered Oct 22 '22 21:10

Akash Kava


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

The two invalidate methods will mark the control's measure or arrange as needing to be executed again, but won't necessarily do it immediately. The UpdateLayout will force it to execute some updates immediately.

It's a bit of a black box, so you may need to invalidate then call UpdateLayout. Sometimes you may just need to call UpdateLayout.

like image 25
CodeNaked Avatar answered Oct 22 '22 20:10

CodeNaked