aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Wednesday, November 17, 2010 Total Views:  

Several times,this question has been asked that how to print a page in Silverlight, thanks to Microsoft who  have given this print support in Silverlight 4. Before going to start you must have installed Visual Studio 2010 and Silverlight 4.

Let’s start.


Open your Visual Studio 2010, from File -> New Project -> Select Silverlight template -> give a name and click OK button to continue.


Following is the code of  Main.xaml file.
<UserControl x:Class="Silverlight4_Printing.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"
   mc:Ignorable="d"
   d:DesignHeight="400"  d:DesignWidth="560" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

   <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center">
       <sdk:Label Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="label1" VerticalAlignment="Top" Width="297" />
       <Button Content="Print" Height="23" HorizontalAlignment="Left" Margin="66,103,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />

   </Grid>
</UserControl>


Following is the code of  Main.xaml.cs file
       public MainPage()
       {
           InitializeComponent();
           label1.Content = "Welcome to aspxtutorial.com";
       }
       private void button1_Click(object sender, RoutedEventArgs e)
       {
           var document = new PrintDocument();
           document.PrintPage += (s, args) =>
           {
               args.PageVisual = LayoutRoot; args.HasMorePages = false;
               button1.Visibility = Visibility.Collapsed;
           };
           document.EndPrint += (s, args) =>
           {

               button1.Visibility = Visibility.Visible;
           };
           document.Print("Silverlight Print Page");
       }

Output

Download

Silverlight 4 - Printing page.zip (252.13 kb)

See live demo

Protected by Copyscape Online Plagiarism Tool

Comments (14) -

hall effect switch
hall effect switch United States
11/25/2010 12:27:49 PM #

Always dream and shoot higher than you know you can do. Don't bother just to be better hall effect switch

than your contemporaries or predecessors. Try to be better than yourself.

silver charms bracelets
silver charms bracelets United States
11/29/2010 2:59:00 PM #

Hi webmaster - This is by far the best looking site I’ve seen. It was completely easy to

navigate and it was easy to look for the information I needed. Fantastic layout and great

content! Every site should have that. Awesome job

Aamir Hasan
Aamir Hasan United States
11/30/2010 5:03:51 AM #

Thank you

Mahwish Akhtar
Mahwish Akhtar
12/18/2010 4:12:52 PM #

what is Silverlight?

send flowers uk
send flowers uk United Kingdom
1/31/2011 11:38:36 PM #

Really your post is really very good and I appreciate it. It’s hard to sort the good from the bad sometimes, but I think you’ve nailed it. You write very well which is amazing. I really impressed by your post.

Cams
Cams United States
5/12/2011 5:52:36 AM #

I want to say that I don’t think I’ve read anything so true in a long time.  You’ve got a lot of great ideas, a great deal of perspective.  I think that you definitely have something important to say and I’m going to back it 110%, man.  Good job keeping this subject alive and interesting!

SEO Pakistan
SEO Pakistan United States
5/18/2011 3:45:41 AM #

This is easier and surely gives comfort to internet users. Thanks for sharing. Post like this offers great benefit. Thank you!

sfewfadsf
sfewfadsf People's Republic of China
5/25/2011 9:49:03 PM #

dsad

sfewfadsf
sfewfadsf People's Republic of China
5/25/2011 9:50:05 PM #

suply cheap nhl nfl jerseys from nhl nfl jerseys cheap www.nhlnfljerseyscheap.com

seo company
seo company United States
5/29/2011 9:54:37 PM #

It is my great pleasure to visit your website and to enjoy your great post here. I like it very much. I know that you put much attention for these articles, as all of them make sense and are very useful

Mulberry for Target
Mulberry for Target People's Republic of China
8/18/2011 8:30:51 PM #

Mulberry Shoulder Bag, girls throughout purple, Roxanne can be normally a new extraordinary target bought, plus exclusively mtsesyha theorized in several job faraway from your escape time frame on this Mulberry Alexa Bag special occasion plus just about obtained this rocks exploring handbag.

male enhancement
male enhancement United States
10/24/2011 5:43:28 AM #

great post.. i really enjoyed it

North Face Jackets On Sale
North Face Jackets On Sale People's Republic of China
10/24/2011 10:21:20 PM #

If you bargin for the goods, you can get the reducement. But there is a very easy way for getting it. Just waiting for the discount season. Just look here North Face Jackets On Sale.So you can get the discount here. Among so many kinds of North Face Jackets, you can final pick out your favorite one.

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5