Evgeny Pokhilko’s Weblog

Dedicated to software development

Measure Size Of Rendered Text In WPF

Problem: Get the size that arbitrary text will take to adjust width, height of a control or control wrapping.

Solution:

FormattedText formattedText = new FormattedText(text,
  Thread.CurrentThread.CurrentCulture,
  FlowDirection.LeftToRight,
  new Typeface(fontFamilyName),
  fontSize,
  Brushes.Black);
return formattedText.Width;

October 20, 2010 Posted by | .NET, WPF | , | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.