title: Layout measurement override of element should not return NaN values as its DesiredSize
body: <p>I've run into a similar issue when I try to call <code>Measure</code> and pass the dynamically calculated size to that method:</p>
  
  <blockquote>
    <p>Layout measurement override of element 'System.Windows.Controls.StackPanel' should not return NaN values as its DesiredSize.</p>
  </blockquote>
  
  <p>I am trying to create a StackPanel on the fly and print it. Here's my code:</p>
  
  <pre><code>StackPanel printPanel = new StackPanel();
  
  PrintableArea.Children.Remove(ChartBorder);
  printPanel.Children.Add(ChartBorder);
  
  //Get selected printer capabilities
  System.Printing.PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket);
  
  //Get scale of the print wrt to screen of visual
  double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / printPanel.ActualWidth, capabilities.PageImageableArea.ExtentHeight / printPanel.ActualHeight);
  
  //Transform the Visual to scale
  printPanel.LayoutTransform = new ScaleTransform(scale, scale);
  
  //Get the size of the printer page
  Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
  
  //Update the layout of the visual to the printer page size.
  printPanel.Measure(sz);
  printPanel.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
  
  dialog.PrintVisual(printPanel, "Test");
  </code></pre>
  
  <p>Any clue what could be the cause of this? And the strange thing is this happens only with <code>StackPanel</code>. If I try to create a simple <code>TextBlock</code> for testing purpose and try to print that, everything works fine with no errors. I was wondering what's different when we call <code>Measure</code> for <code>StackPanel</code>?</p>
  
  <p>Any help to fix this issue would be really great!</p>