title: How to calculate height & width of string with particular font family & font size?
body: <p>I want to achieve <a href="https://stackoverflow.com/questions/2070365/how-to-generate-an-image-from-text-on-fly-at-runtime">this</a> in WinRT app.</p>
  
  <p>I know I can use SharpDX to render the text, you can check out my <a href="http://www.codeproject.com/Articles/513187/Paste-Date-Time-Stamp-While-Capturing-Image-in-Win" rel="nofollow noreferrer">CodeProject article</a>. <strike>I want to know how to create a white background image of size with capacity to accommodate the text with font-family Segoe UI and font size of 16?</strike></p>
  
  <p>I've found how to create white image. But how can I calculate the size of the long string (like 2000+ characters), which is going to be render on white image ?</p>
  
  <p>I've checked <a href="https://stackoverflow.com/questions/10556019/how-to-calculate-the-textbock-height-and-width-in-on-load-if-i-create-textblock">how to calculate the textbock height and width in on load if i create textblock from code?</a>, but I am getting incorrect value. I don't know what to pass as arguments in <code>Arrange(...)</code> &amp; <code>Measure(...)</code> methods. I am passing <code>Window.Current.Bounds</code> as parameter. I want something like this.</p>
  
  <pre><code>private double GetHeight(string Text, string fontFamily, double fontSize)
  {
      //TODO:
  }
  </code></pre>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>According to <a href="https://twitter.com/xyzzer/status/379607288585019393" rel="nofollow noreferrer">Filip's suggestion</a> I tried this, but it's also giving me incorrect value.</p>
  
  <pre><code>TextBlock textBlock = new TextBlock();
  private double GetHeight(string Text)
  {
      var scroller = new ScrollViewer();
      scroller.Height = Window.Current.Bounds.Height;
      scroller.Width = Window.Current.Bounds.Width;
      scroller.Content = textBlock;
  
      textBlock.Text = Text;
      textBlock.FontFamily = new FontFamily("Segoe UI");
      textBlock.FontSize = 40;
      textBlock.TextWrapping = TextWrapping.Wrap;
      textBlock.Arrange(new Rect(0, 0, 9000000000, 9000000000));
      textBlock.Measure(new Size(9000000000, 9000000000));
  
      root.Children.Add(scroller);
  
      return textBlock.ActualHeight; //return 478.82919311523437
  }
  
  // root is the Root grid of the app, there's nothing in XAML
  private void root_Tapped_1(object sender, TappedRoutedEventArgs e)
  {
      var aa = textBlock.ActualHeight; //return 2766.5732421875
  }
  </code></pre>