Question

One of the Silverlight 4 features listed in a lot of the PDC documents is Print Preview.

I've searched for examples on how to use this and found nothing so far. Has anyone got this working yet? Can you give me some pointers on how to implement a simple web app with print preview in.

Was it helpful?

Solution 3

I think from the lack of responses and the fact that as Hurricanepkt pointed out in his reply Tim Heuer and others talk about a virtual print which if displying the same thing on the screen could be built quite easily into your own bespoke Print Preview functionality that the Print Preview listed in some lists is actually people misinterpretting what the Virtual Print documents actually are.

OTHER TIPS

I have not seen print preview as any of them but actual Printing support in which you can control which controls are printed and events based on the printing process.

After looking for a while I found a way to do this by combining some features I found in other projects, but they used it for image manipulation. I tried with printing and it seems to work fine.

Here how it works: Get the base container for the print contents converted to a bitmap by using WriteableBitmap, here I´ll use a Canvas:

WriteableBitmap wb = new WriteableBitmap(this.canvas1, null);

Use this bitmap as a source for a Image control (can be inside a ScrollViewer, what is even better).

this.imagePreview.Height = wb.PixelHeight;
this.imagePreview.Width = wb.PixelWidth;
this.imagePreview.Source = wb;

Set scaling base units (used 1 percent in this case):

Point scale = new Point();      

scale.X = imagePreview.Width/100d;
scale.Y = imagePreview.Height/100d;

Then adjust the scaling using a Slider (optional)

private void vSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {

                imagePreview.Height = scale.Y * vSlider.Value;
                imagePreview.Width = scale.X * vSlider.Value;           
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top