title: Saving WPF Canvas to file without losing quality (Without using Bitmap as intermediary)
body: <p>I've been tasked with creating nomographs for some dynamic refrigerant properties. (<a href="https://duckduckgo.com/?q=nomograph&amp;t=vivaldi&amp;iax=images&amp;ia=images" rel="nofollow noreferrer">Nomograph Examples</a>). Specifically, I have to create a program which takes user input and then generates a printable nomograph graphic. I have to interface with a couple external blackbox .dll's to get some data, so I decided .NET was the best platform for me to use. Seeing as there's no existing tool that lends itself easily to creating very complex graphs where all 4 axes are based on user input, I've built it to just draw lines and text on a WPF canvas. Everything's working great; Zooming, Panning, all that. I have one problem though.</p>
  
  <p>Every answer I've found to saving a WPF canvas to a file, such as a png, has used bitmap as a route to get there. The problem with this, and I have tried it and gotten it to work, is that the resulting image loses all scalability and, depending on the size of the canvas, a lot of quality. XAML should be all vector graphics, and because this is a graph with a lot of information packed into a small area, I need a scalable result.</p>
  
  <p>NOTE: This is <em>NOT</em> a duplicate of all the other "How to save WPF canvas to file" questions.</p>
  
  <p>Things I've tried:</p>
  
  <ol>
  <li>All the other "How to save WPF canvas to file" answers.</li>
  <li>Increasing the dpi input in the <code>RenderTargetBitmap()</code> method. 
  (NOTE: This just zooms the image in on the upper lefthand corner, making it unusable)</li>
  </ol>
  
  <p>Ideas</p>
  
  <p>I think maybe if there's no way to do what I'm asking, something that could also work is simply scaling the canvas and all its child elements to something ridiculously large just before saving, maybe making a copy, and then saving that? Truth is, I'm not at all sure how to go about doing that, and I'd rather see if there's a way to just save to a vector graphic first.</p>
  
  <p>Here's my XAML:</p>
  
  <pre><code>&lt;Window x:Class="RefGraph.Graph"
      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"
      xmlns:local="clr-namespace:RefGraph"
      mc:Ignorable="d"
      Title="Graph" Height="1081" Width="1400"&gt;
  &lt;Grid&gt;
      &lt;Viewbox&gt;
          &lt;Canvas Height="{Binding Path=CanvasHeight}" Width="{Binding Path=CanvasWidth}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,20,0,0" MouseWheel="Canvas_MouseWheel" MouseMove="Canvas_MouseMove" MouseLeftButtonDown="Canvas_MouseLeftButtonDown" MouseLeftButtonUp="Canvas_MouseLeftButtonUp"&gt;
              &lt;Canvas.RenderTransform&gt;
                  &lt;TransformGroup&gt;
                      &lt;TranslateTransform/&gt;
                      &lt;MatrixTransform/&gt;
                  &lt;/TransformGroup&gt;
              &lt;/Canvas.RenderTransform&gt;
              &lt;ContentPresenter Content="{Binding Canvas}"&gt;&lt;/ContentPresenter&gt;
          &lt;/Canvas&gt;
      &lt;/Viewbox&gt;
      &lt;Menu x:Name="Menu_Main" Width="{Binding ActualWidth, ElementName=DockPanel_Menu}" Height="20" VerticalAlignment="Top"&gt;
          &lt;MenuItem x:Name="Menu_File" Header="_File"&gt;
              &lt;MenuItem x:Name="MenuItem_Save" Header="_Save" InputGestureText="Ctrl+S" VerticalAlignment="Top" HorizontalAlignment="Left" Click="MenuItem_Save_Click"/&gt;
              &lt;MenuItem x:Name="MenuItem_SaveAs" Header="_Save As" InputGestureText="Ctrl+Shift+S" VerticalAlignment="Top" HorizontalAlignment="Left" /&gt;
              &lt;MenuItem x:Name="MenuItem_Print" Header="_Print" InputGestureText="Ctrl+P" VerticalAlignment="Top" HorizontalAlignment="Left" /&gt;
              &lt;MenuItem x:Name="MenuItem_PrintPreview" Header="_Print Preview" InputGestureText="Ctrl+Shift+P" VerticalAlignment="Top" HorizontalAlignment="Left"/&gt;
              &lt;Separator /&gt;
              &lt;MenuItem Header="_Exit" InputGestureText="Ctrl+X" VerticalAlignment="Top" HorizontalAlignment="Left" /&gt;
              &lt;/MenuItem&gt;
      &lt;/Menu&gt;
  &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>I should note that there are many child elements getting dynamically added to the canvas before saving.</p>
  
  <p>Another note: For some reason, I thought PNGs were vector graphics. I honestly don't know why. I suppose this question isn't specifically about PNGs, but more about saving a canvas without awful quality, as would be necessitated by using the existing answers on this site. I've edited the question to reflect this, and I've posted an answer as well. </p>