Reputation: 366
I am new to Silverlight, i have given a task to create a print preview template for a GIS Web Application for my company. My requirement is as follows:
1) When i click on the print preview button on my mainpage it should popup a new print preview window 2) The preview window should have mainpage content 3) It should have a print button to print it. 4) It should have next page and previous page option 5) A zoom icon/slider to zoom in and zoom out the preview contents
Upto now i have just a added a preview button on my mainpage, which on click opening a new xaml window and on that window i have set contents like this.
Here is the view of PrintPreview.xaml
<Grid x:Name="LayoutRoot" Background="White">
<Canvas x:Name="m_canvas" Height="490" VerticalAlignment="Top" Margin="0,0,60,0">
<Button x:Name="m_btn_print" Canvas.Top="5" Canvas.Left="5" Width="32" Height="32" Click="m_btn_print_Click">
<Image Source="Images/print.png" Stretch="Fill" />
<ToolTipService.ToolTip>
<ToolTip Content="Print"></ToolTip>
</ToolTipService.ToolTip>
</Button>
<Button x:Name="m_btn_prev_page" Canvas.Top="5" Canvas.Left="45" Width="32" Height="32" Click="m_btn_prev_page_Click">
<Image Source="Images/arrow.left.png" Stretch="Fill"/>
<ToolTipService.ToolTip>
<ToolTip Content="Previous Page"></ToolTip>
</ToolTipService.ToolTip>
</Button>
<Button x:Name="m_btn_next_page" Canvas.Top="5" Canvas.Left="85" Width="32" Height="32" Click="m_btn_next_page_Click">
<Image Source="Images/arrow.right.png" Stretch="Fill"/>
<ToolTipService.ToolTip>
<ToolTip Content="Next Page"></ToolTip>
</ToolTipService.ToolTip>
</Button>
<Slider x:Name="m_sld_size" Minimum="50" Maximum="125" Value="100" SmallChange="5" LargeChange="5" ValueChanged="m_sld_size_ValueChanged"
Canvas.Top="15" Canvas.Left="245" VerticalAlignment="Top" HorizontalAlignment="Right" Width="80" />
<TextBlock x:Name="m_lbl_size" Canvas.Top="2" Canvas.Left="265" FontSize="9" Text="Zoom" Foreground="Black" />
<Canvas x:Name="m_canvas_print" Canvas.Top="40" Canvas.Left="5" Width="317" Height="445" Background="White"
VerticalAlignment="Top" HorizontalAlignment="Left">
</Canvas>
</Canvas>
</Grid>
Now what should be my code behind, how should i show the mainpage.xaml content on this preview. Please help its urgent
Thanks in advance.
Upvotes: 0
Views: 1159
Reputation: 46
My first word of advise is not to use a canvas object unless you are filing it in with something that is the same every time you print it. If you are printing dynamic data values that can change based on the time it is printed I would move to a stack panel or grid.
That being said you will need to wire up the print function to print the m_cavas_print object when a user presses the print button. I have added some sample print code below.
PrintDocument pd = new PrintDocument();
pd.PrintPage += (s, e) =>
{
e.PageVisual = m_cavas_print;
};
pd.Print("MainPageContent");
This is the basic principle behind printing. You can put this in your print button click event handler and it will print whatever is in the canvas. I used a lambda expression here to handle the print page event but you can use a separate method as well.
Upvotes: 1