In this article we are going to see how to use printing options with Windows Store application development. In Traditional app development printing is one find of a feature that is required to print the content directly from the application rather taking the content and printing from other supported applications. In Windows Store app development we have a contract which is used to print in the modern way which is called Print Contract. With this we can see the preview of the content that to be printed as well and have a final print to the printer. Your app need to register with the print contract, so that the printing becomes available from the Device charm by sliding over the right corner of the device.
Printing basically in XAML/C# application is derived from the PrintManager object, through which you need to register the object and create a PrintTask object which creates the contract to print from the application. After the contract is registered for the print contract the default UI that has been predefined can be printed from the application directly. By default all the apps that are registered with Print Contract will have the Print preview enabled and has the functions that are associated readily available.
Let us see the steps on how to incorporate printing option to the Windows Store app easily. Open the Windows Store app where we need to add the printing option or create a new project from Visual Studio 2013 and start implementing the below solution. As a first step we need to register the printer and then MyPrint is the new xaml file which has the content that needs to be printed.[code:c#]
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
/// An empty page that can be used on its own or navigated to within a Frame.
public partial class MainPage : Page
protected PrintDocument printDocument = null;
protected IPrintDocumentSource printDocumentSource = null;
internal List<UIElement> printPreviewPages = null;
protected FrameworkElement firstPage;
private void Button_Click(object sender, RoutedEventArgs e)
MyPrint myprnt = new MyPrint();
StackPanel header = (StackPanel)myprnt.FindName("header");
header.Visibility = Windows.UI.Xaml.Visibility.Visible;
protected virtual Canvas PrintingRoot
return FindName("printingRoot") as Canvas;
public virtual void RegisterForPrinting()
printDocument = new PrintDocument();
printDocumentSource = printDocument.DocumentSource;