Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Important thing to note : <strong>You can use XpsDocumentWriter even when printing directly to a physical printer. Don't make the mistake I did of avoiding it just because you're not creating an .xps file!</strong></p> <p>Anyway - I had this same problem, and none of the <code>DoEvents()</code> hacks seemed to work. I also wasn't particularly happy about having to use them in the first place. In my situation some of the databound controls printed fine, but some others (nested UserControls) didnt. It was as if only one 'level' was being databound and the rest wouldn't bind even with a 'DoEvents()' hack.</p> <p>The solution was simple though. Use XpsDocumentWriter like this. it will open a dialog where you can choose whichever installed physical printer you want. </p> <pre><code> // 8.5 x 11 paper Size sz = new Size(96 * 8.5, 96 * 11); // create your visual (this is a WPF UserControl) var template = new PackingSlipTemplate() { DataContext = new PackingSlipViewModel(order) }; // arrange template.Measure(sz); template.Arrange(new Rect(sz)); template.UpdateLayout(); // print to XpsDocumentWriter // this will open a dialog and you can print to any installed printer // not just a 'virtual' .xps file PrintDocumentImageableArea area = null; XpsDocumentWriter xps = PrintQueue.CreateXpsDocumentWriter(ref area,); xps.Write(template); </code></pre> <p>I found the OReilly book on '<a href="http://rads.stackoverflow.com/amzn/click/0596510373" rel="nofollow noreferrer">Programming WPF</a>' quite useful with its chapter on <a href="http://books.google.com/books?id=558i6t1dKEAC&amp;lpg=PA522&amp;ots=gZweKFGWJO&amp;dq=wpf%20printing%20binding%20%20xps&amp;pg=PA522#v=snippet&amp;q=printing&amp;f=false" rel="nofollow noreferrer">Printing - found through Google Books</a>.</p> <hr> <p>If you don't want a print dialog to appear, but want to print directly to the default printer you can do the following. (For me the application is to print packing slips in a warehouse environment - and I don't want a dialog popping up every time).</p> <pre><code> var template = new PackingSlipTemplate() { DataContext = new PackingSlipViewModel(orders.Single()) }; // arrange template.Measure(sz); template.Arrange(new Rect(sz)); template.UpdateLayout(); LocalPrintServer localPrintServer = new LocalPrintServer(); var defaultPrintQueue = localPrintServer.DefaultPrintQueue; XpsDocumentWriter xps = PrintQueue.CreateXpsDocumentWriter(defaultPrintQueue); xps.Write(template, defaultPrinter.DefaultPrintTicket); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload