Simple Printing in c# XAML App? -


so need print label windows 8 app,(c# xaml), , of samples i've found overcomplicated needs. content seperate page, containing text block , image, filled when page loads, need print page. there simplified method printing ( ie, no using richtextbox , overflows etc) single simple page. interested, page need print:

<page x:class="storeageapp.outputforlabel" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:storeageapp" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="d" width="300" height="200"> <grid x:name="printablearea">      <grid.rowdefinitions>          <rowdefinition height="3*"/>         <rowdefinition height="3*"/>      </grid.rowdefinitions>       <stackpanel x:name="header" grid.row="0" grid.columnspan="2" height="60"  visibility="collapsed">      </stackpanel>      <textblock x:name="uid" text="hello world" horizontalalignment="center" verticalalignment="center" fontsize="24" />      <image source="" x:name="scenarioimage"  horizontalalignment="center" grid.row="1" grid.column="0" margin="10"/>      <stackpanel x:name="footer"  grid.row="4" grid.column="0" verticalalignment="top" visibility="collapsed">      </stackpanel> </grid> </page> 

i'd happy if there way print image can't figure out. thanks. edit: in windows store app sorry, not wpf.

you can perform basic printing in wpf using printdialog class. example in linked page:

private void invokeprint(object sender, routedeventargs e) {     // create print dialog object , set options     printdialog pdialog = new printdialog();     pdialog.pagerangeselection = pagerangeselection.allpages;     pdialog.userpagerangeenabled = true;      // display dialog. returns true if user presses print button.     nullable<boolean> print = pdialog.showdialog();     if (print == true)     {         xpsdocument xpsdocument = new xpsdocument("c:\\fixeddocumentsequence.xps", fileaccess.readwrite);         fixeddocumentsequence fixeddocseq = xpsdocument.getfixeddocumentsequence();         pdialog.printdocument(fixeddocseq.documentpaginator, "test print job");     } } 

however, possible print less code that:

printdialog printdialog = new printdialog(); document.columnwidth = printdialog.printableareawidth; if (printdialog.showdialog() == true) printdialog.printdocument(     ((idocumentpaginatorsource)document).documentpaginator, "flow document print job"); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -