Go Back   TechArena Community > Software > Windows Software
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Not able to print multiple pages in Silverlight 4

Windows Software


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-08-2010
Member
 
Join Date: Apr 2010
Posts: 81
sad Not able to print multiple pages in Silverlight 4
  

I am having issues while printing the multiple pages in Silverlight. I am using the beta version of Silverlight 4. I am using the HasMorePages in it, but still I am having the problem while printing the multiple pages.: I don't know much about it, but I know the basic things. The HasMorePages property remember that indicates if our document is to print more pages, if HasMorePages is true then the event will fire again PrintPage until HasMorePages is false. I think I am right in this logic. Please help me in solving the problem.

Reply With Quote
  #2  
Old 05-08-2010
Member
 
Join Date: Dec 2008
Posts: 128
Re: Not able to print multiple pages in Silverlight 4

We see that we have a ListBox which contains a list of music albums. In addition we are changing the DataTemplate to show a better way each of these elements. The following snippet shows the XAML of the application:

Code:
<UserControl x: Class = "Demo.SL4.ImpresionMultiple.MainPage" 
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns: d = "http://schemas.microsoft.com/expression/blend/2008" 
xmlns: mc = "http://schemas.openxmlformats.org/markup-compatibility/2006" 
xmlns: local = "clr-namespace: Demo.SL4.ImpresionMultiple" 
mc: ignore = "d" 
d: DesignHeight = "300" d: DesignWidth = "500"> 
<UserControl.Resources> 
<Local: Albums x: Key = "albums" /> 

<DataTemplate x: Key = "VistaDataTemplate"> 
<Grid> 
<Grid.ColumnDefinitions> 
<ColumnDefinition Width = "100" /> 
<ColumnDefinition /> 
</ Grid.ColumnDefinitions> 
<Border BorderBrush = "Black" Padding = "3" BorderThickness = "2" CornerRadius = "10"> 
<Image Source = "(Binding picture) 
Width = "100" /> 
                 </ Border> 
<StackPanel Grid.Column = "1"> 
<TextBlock Text = "(Binding Title)" 
FontSize = "20" /> 
<TextBlock Text = "(Binding Banda)" /> 
                 </ StackPanel> 
             </ Grid> 
</ DataTemplate> 
</ UserControl.Resources> 


<Grid x: Name = "LayoutRoot" Background = "White" DataContext = "(StaticResource albums)"> 
<Grid.ColumnDefinitions> 
<ColumnDefinition Width = "Auto" /> 
<ColumnDefinition Width = "*" /> 
</ Grid.ColumnDefinitions> 
<ListBox Grid.Column = "1" 
HorizontalAlignment = "Left" 
Margin = "5" 
Name = "listBox1" 
VerticalAlignment = "Top" 
Width = "450" 
Height = "450" 
ItemsSource = "(Binding)" 
ItemTemplate = "(StaticResource VistaDataTemplate)" /> 
<StackPanel Height = "228" 
HorizontalAlignment = "Left" 
Name = "stackPanel1" 
VerticalAlignment = "Top" 
Margin = "5"> 
<Button Height = "50" 
Name = "button1" 
Width = "120"> 
<Button.Content> 
<StackPanel> 
<TextBlock HorizontalAlignment = "Center"> Print </ TextBlock> 
<TextBlock HorizontalAlignment = "Center"> ListBox </ TextBlock> 
</ StackPanel> 
</ Button.Content> 
</ Button> 
<Button Height = "50" 
Name = "button2" 
Width = "120"> 
<Button.Content> 
<StackPanel> 
<TextBlock HorizontalAlignment = "Center"> Print </ TextBlock> 
<TextBlock HorizontalAlignment = "Center"> Custom </ TextBlock> 
</ StackPanel> 
</ Button.Content> 
</ Button> 
</ StackPanel> 
</ Grid> 
</ UserControl>
I think after looking at this sample of coding you should get an idea about printing the multiple pages in Silverlight 4.
Reply With Quote
  #3  
Old 05-08-2010
Member
 
Join Date: Mar 2008
Posts: 433
Re: Not able to print multiple pages in Silverlight 4

Printing Elements - PageVisual property object in the event arguments ultimately PrintPage indicates what the content to print and this content of the XAML tree or not. That is, if we set the ListBox as PageVisual ...

Code:
pd. PrintPage + = (s, a) => 
( 
// Set the ListBox as PageVisual 
to.PageVisual = listBox1; 
);
Reply With Quote
  #4  
Old 05-08-2010
Member
 
Join Date: Feb 2008
Posts: 121
Re: Not able to print multiple pages in Silverlight 4

We can achieve a higher degree of customization to dynamically create XAML content we want to print. In the case of this example dynamically generate a Canvas that contains a header, and a ItemsControl to display each and every one of the elements to print. Besides the above, we will ensure that enables printing multiple pages to print the records on each page correctly.
Reply With Quote
  #5  
Old 05-08-2010
Member
 
Join Date: Feb 2008
Posts: 137
Re: Not able to print multiple pages in Silverlight 4

Canvas - You create a Canvas that has the same size of the print area available, depending on the printer selected:
Code:
pd. PrintPage + = (s, a) => 
( 
canvas = new Canvas () (Width = a.PrintableArea.Width, Height = a.PrintableArea.Height); 
...
Header - For each page to print will add a header containing a logo to the left of the header title centered, and text indicating the current page number.

Item List - This is the most important part of this scenario. We need to stand the fact that there will be more than one page when printing. In the example in this article we have an object called Rocket (List <Album>) which has a total of 42 albums.
Reply With Quote
  #6  
Old 05-08-2010
Member
 
Join Date: Feb 2008
Posts: 129
Re: Not able to print multiple pages in Silverlight 4

For custom printing call PrintDataTemplate create another DataTemplate which will display differently the same elements of the screen. For example, we will remove the image from each album and deploy the elements within a grid with four columns. The columns will show Title, Banda, Inventory and Release Date. The following excerpt shows the DataTemplate XAML for printing:

Code:
<ColumnDefinition Width = "120" /> 
<ColumnDefinition Width = "100" /> 
<ColumnDefinition Width = "100" /> 
</ Grid.ColumnDefinitions> 
<Grid.RowDefinitions> 
<RowDefinition Height = "40" /> 
</ Grid.RowDefinitions> 
<TextBlock Text = "(Binding Title)" FontWeight = "Bold" Grid.Column = "0" /> 
<TextBlock Text = "(Binding) Banda" Grid.Column = "1" /> 
<TextBlock Text = "(Binding) Inventory" Grid.Column = "2" /> 
<TextBlock Text = "(Binding ReleaseDate) 
Grid.Column = "3" /> 
</ Grid> 
</ DataTemplate>
Reply With Quote
  #7  
Old 05-08-2010
Member
 
Join Date: Oct 2008
Posts: 180
Re: Not able to print multiple pages in Silverlight 4

Finally, in the event PrintPage invoke the methods of creating the header and the creation of items per page:

Code:
... 
CreateHeader ("List of albums"); 


CreateLilst (currentPage) 

to.PageVisual = canvas; 

to.HasMorePages =! (currentPage == totalPage) 
...
Very important in the above code is the property value HasMorePages. In this example we are indicating whether there are more pages if the count (variable currentPage) is different from the total number of pages (variable totalPage). Recall that if is true HasMorePages , the event will fire again PrintPage, causing the impression of each and every one of the listing pages.
Reply With Quote
Reply

  TechArena Community > Software > Windows Software
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Not able to print multiple pages in Silverlight 4"
Thread Thread Starter Forum Replies Last Post
Pages cut off when using Google Cloud Print to print from HP PSC1315xi printer Shoana Technology & Internet 3 27-02-2012 09:21 AM
Silverlight is installed but not running on web pages Bohdan Technology & Internet 5 19-04-2011 10:27 PM
Print large photo on multiple pages? OctAvio2011 Windows Software 5 29-09-2010 03:45 AM
How can I print a picture on multiple pages to make it bigger? NIcaBoy MS Office Support 1 13-05-2009 10:41 PM
Cannot print from web pages RonaldA Technology & Internet 3 09-03-2009 06:43 PM


All times are GMT +5.5. The time now is 03:29 PM.