0

i am working in wpf,i have a richtextbox with some contents.if the contents are exceeded to richtextbox i want to hide bottom border.if the content within the richtextbox i want to show the bottom border.Now i am using the below code to bring the exceeded content to view in richtextbox.

 FrameworkContentElement fce = (startPos.Parent as FrameworkContentElement);
            if (fce != null)
            {
                fce.BringIntoView();
            }

But i want to display the bottom border,once the last word shown in that richtextbox.How to achieve this?

Note: I already known how to show bottom border dynamically.but i want to know last word are displayed within the richtextbox or not?

Regards Arjun

arjun sanju
  • 135
  • 1
  • 1
  • 12

1 Answers1

1

I can provide you with a method to check whether the upper left corner of a character is visible or not. Create a class library Tools with the following content:

public class ToolsRtb
{
    public static bool PositionVisibleIs(RichTextBox rtb, TextPointer pos)
    {
        // Rectangle around the character to check
        Rect r = pos.GetCharacterRect(LogicalDirection.Forward);

        // Upper left corner of the rectangle ...
        Point upperLeftCorner = r.Location;

        HitTestResult result = VisualTreeHelper.HitTest(rtb, upperLeftCorner);

        // ... is visible?
        if (result != null)
            return true;
        else
            return false;
    }   
}

Note that PositionVisibleIs(...) is a static method and not dedicated to a specific object. In the code behind file of the window which contains your RichTextBox use the method like this:

// Is the last character of the current document visible?
if (ToolsRtb.PositionVisibleIs(rtb, rtb.Document.ContentEnd) == true)
{
    ...
}

Hope this helps.

Pollitzer
  • 1,580
  • 3
  • 18
  • 28
  • @ Pollitzer : its working fine.but after one panning,i want to clear current content and load new content,at that time that Rect value same as previous.but i want to clear it and act like same as before panning.I mean Once the result value is comes null i do some panning after i reload data the result value also null.how to clear that value? – arjun sanju Jan 14 '16 at 04:49
  • 1
    After clearing the `RichTextBox` and loading new content you must call PositionVisibleIs(rtb, rtb.Document.ContentEnd) again because last visible position will be different from content to content, depending on font size, upper case / lower case, bold / normal etc. – Pollitzer Jan 14 '16 at 08:16
  • @ Pollitzer : Thanks.But PositionVIsibles come from which class?Can u show in code? – arjun sanju Jan 14 '16 at 08:29
  • @ Pollitzer : Can u look at this link.U got what i exactly need. [link] (http://stackoverflow.com/questions/34783272/clear-pageup-pagedown-panning-values-after-clear-and-reload-content-in-wpf-richt) – arjun sanju Jan 14 '16 at 09:27