locked
measure text height in a RichTextBlock RRS feed

  • Question

  • I want to measure the height of text in a RichTextBlock so that I can resize it at runtime. I know that I will have to find the number of lines and height of each line but how can I do so ?

    Thursday, July 18, 2013 12:35 PM

Answers

  • I don't know the exact answer for this, but perhaps you could measure the height of a textbox with a single line in it, then divide that into the height of your textbox with multiple lines.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, July 23, 2013 2:09 PM
    Moderator

All replies

  • Please see this post: http://social.msdn.microsoft.com/Forums/en-US/f1f2a1ae-7237-44c3-aee0-cd553a01741a/get-charachter-height-in-metro

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, July 18, 2013 6:13 PM
    Moderator
  • This post shows how I can find the height of a character. How can I find the number of lines in textblock ?
    Friday, July 19, 2013 8:53 AM
  • I have placed the textblock inside a stackpanel with a fixed Height and this is part of a user control. So if the content inside the textblock is more than the size of stackpanel, then the ActualHeight of stackpanel is more than the Height. By taking the difference of ActualHeight and Height, I know by how much value I should resize the user control and stackpanel so that it displays the full content of textblock.
    Tuesday, July 23, 2013 6:29 AM
  • I don't know the exact answer for this, but perhaps you could measure the height of a textbox with a single line in it, then divide that into the height of your textbox with multiple lines.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, July 23, 2013 2:09 PM
    Moderator