none
How to find the content height of the Flow document? RRS feed

  • Question

  • Hi Dudes,

    I have a RichTextBox control in my application. When the user types the content inside the RichTextBox and clicks ok i need to validate such that the content that the user entered should not overflow the controls Height. So i need to find the height of the FlowDocument property of the RichTextBox Control. I dont have an option to find the height

    found one way from surfing around

           double GetDocumentHeight()
            {
                Rect rectStart = Document.ContentStart.GetCharacterRect(LogicalDirection.Forward);
                Rect rectEnd = Document.ContentEnd.GetCharacterRect(LogicalDirection.Forward);
                if (!Double.IsInfinity(rectEnd.Bottom) && !Double.IsInfinity(rectStart.Top))
                {
                    return rectEnd.Bottom - rectStart.Top;
                }
                else
                {
                    return 0d;
                }

            }

    This works good, but unforunately it is not working when the control is not present physically.

    Is there any other way to find the Height of the FlowDocument content height

    Thanks in advance

    Ramesh R

    Saturday, August 28, 2010 5:30 AM

Answers

  • Hi Rao,

    Thanks for the reply.

    But the Extentheight property of the RichTextBox will be set only when the document changed.

    Which is not supported by my app requirements.

    To add more clarity, i have two RTB controls. one used to edit the text content and another used to assign the edited content. The end user is  allowed to edit only one control. But he can change the height of the non editable control. The problem occurs when the end user resized the non editable control

    i should validate if the user changes the height of the non editable control.

    I Found the solution. you need to set the style for the Paragraph inside the RichTextBox.

    <Style TargetType="{x:Type Paragraph}">
                        <Setter Property="Margin" Value="0"/>
                    </Style>

    Now, its working fine

    Any how, thanks for your interest

    Thanks

    Ramesh R

    Saturday, August 28, 2010 10:24 AM

All replies

  • Hi Ramesh,

    u can calculate the RichTextBox's content height using ExtentHeight property of the RichTextBox

     double extebt = myRichTextBox.ExtentHeight;
          double actual = myRichTextBox.ActualHeight;

    ExtentHeight will give the content height of the RichTextBox

     

    Saturday, August 28, 2010 6:01 AM
  • hi there ,

    Please go through this Link you might get Idea from this Discussion

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/25a08bda-dc5e-4689-a6b0-7d4d78aff06b

    Regards

     

    Saturday, August 28, 2010 6:09 AM
  • Hi Rao,

    Thanks for the reply.

    But the Extentheight property of the RichTextBox will be set only when the document changed.

    Which is not supported by my app requirements.

    To add more clarity, i have two RTB controls. one used to edit the text content and another used to assign the edited content. The end user is  allowed to edit only one control. But he can change the height of the non editable control. The problem occurs when the end user resized the non editable control

    i should validate if the user changes the height of the non editable control.

    I Found the solution. you need to set the style for the Paragraph inside the RichTextBox.

    <Style TargetType="{x:Type Paragraph}">
                        <Setter Property="Margin" Value="0"/>
                    </Style>

    Now, its working fine

    Any how, thanks for your interest

    Thanks

    Ramesh R

    Saturday, August 28, 2010 10:24 AM