greenoldman
greenoldman

Reputation: 21062

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

Remarks

Before I ask, let me focus on words:

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.

Upvotes: 1

Views: 317

Answers (1)

BrokenGlass
BrokenGlass

Reputation: 160932

check out this SO answer: Length of string that will fit in a specific width - given all font properties and the actual text you can determine the width the text would take with the FormattedText class.

Upvotes: 1

Related Questions