Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the resource that you want to print is part of your application resources, i.e. added to the App.xaml file directly, as shown below, or via merged dictionaries, then you should be able to just new up a visual element and set the content. Here I am using this.FindResource() to get an instance of the resource to set as the content. </p> <p><strong>Note:</strong> You don't have to display the newed-up Page in order to print it.</p> <p><strong>Application Resource</strong></p> <pre><code>&lt;Application x:Class="PrintTest.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"&gt; &lt;Application.Resources&gt; &lt;Grid x:Key="PrintTestResource"&gt; &lt;TextBlock FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center"&gt;Hello World&lt;/TextBlock&gt; &lt;/Grid&gt; &lt;/Application.Resources&gt; &lt;/Application&gt; </code></pre> <p><strong>Print Code</strong></p> <pre><code>public void Print() { var printDialog = new PrintDialog(); if (printDialog.ShowDialog().Value) { var printCapabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket); var printSize = new Size(printCapabilities.PageImageableArea.ExtentWidth, printCapabilities.PageImageableArea.ExtentHeight); var printPage = new Page(); printPage.Content = this.FindResource("PrintTestResource"); printPage.Measure(printSize); printPage.Arrange(new Rect(new Point(printCapabilities.PageImageableArea.OriginWidth, printCapabilities.PageImageableArea.OriginHeight), printSize)); printDialog.PrintVisual(printPage, String.Empty); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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