Results 1 to 7 of 7

Thread: Not able to print multiple pages in Silverlight 4

  1. #1
    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.

  2. #2
    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.

  3. #3
    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; 
    );

  4. #4
    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.

  5. #5
    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.

  6. #6
    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>

  7. #7
    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.

Similar Threads

  1. Replies: 3
    Last Post: 27-02-2012, 10:21 AM
  2. Silverlight is installed but not running on web pages
    By Bohdan in forum Technology & Internet
    Replies: 5
    Last Post: 19-04-2011, 10:27 PM
  3. Print large photo on multiple pages?
    By OctAvio2011 in forum Windows Software
    Replies: 5
    Last Post: 29-09-2010, 03:45 AM
  4. Replies: 1
    Last Post: 13-05-2009, 10:41 PM
  5. Cannot print from web pages
    By RonaldA in forum Technology & Internet
    Replies: 3
    Last Post: 09-03-2009, 06:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,620,311.45260 seconds with 17 queries