wpf - FormattedText.GetMaxTextWidths returns null - why? -


I'm trying to figure out how wide my text is, that's my code:

 

The problem is that w is always null. do you know?

formatted text class does not tell you that the maximum line width is the second Works the way; You tell it the maximum width and it shows how the text is displayed.

This MSDN article has more information:

Taking the sample code and overwriting on ownership The event of a window, that is, a line of text looks like this When an obstacle is not kept on the width:

alt text

When Maxextext is set to 300:

Alt text

and when setsMaxTextWidths passes in a double array of {200, 500, 100}} (last width is all sh Is used for Shi lines when there are more rows than array entries):

Alt text

In all the above examples, I have left MaxTextHeight set to 240.

Notes If you want to run the code from the article in the OnRender event in a window :

  • background property transparent
  • Add a line of code to draw a white background behind the text: < / Ul>

      // Draw a white background drawing. Content Drawengeline (Brush White, Blank, New Rect (new point (0, 0), new shape (this bit, this .high)); Draw drawing formatted text string to // control drawing DrawingContext.DrawText (formatted text, new point (10, 10));  

Comments