How to get the width of the whole text of the widget in WPF?

Posted by macias on Stack Overflow See other posts from Stack Overflow or by macias
Published on 2010-12-31T23:25:31Z Indexed on 2011/01/01 7:54 UTC
Read the original article Hit count: 194

Filed under:
|

Remarks

Before I ask, let me focus on words:

  • the length of "i" is 1
  • the length of "w" is 1
  • the render width of "w" is greater than "i" (except for monospace font) -- I am interested in this and from now on, I would simply write "width"

The problem (small picture)

Let's say I have incredible long text set for TextBlock widget which width is 100. And the text does not fit (the text is clipped -- i.e. only small portion of text is visible).

The question is -- what is the width of the entire text (visible + not visible parts)?

The background (big picture)

I have a window width DataGrid (WPF standard) as main widget which contains text. I try to resize window and DataGrid in such way, that all texts will be visible without need of resizing and/or scrolling.

I focus on width. The size of the window vs. size of the screen is not an issue, the text is so short that it would fit even on netbook screen.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf