PositionHandlerWalker

2 posts, 0 answers
  1. Terje
    Terje avatar
    6 posts
    Member since:
    Jun 2009

    Posted 12 Feb 2013 Link to this post

    Hello Telerik

    In my appication I have a series of vertically stacked RichTextBoxes. What I would like to do is to detect if the Caret is on the first or last line in the document, so that I can move the the focus and set the Caret in the previous or next RTB, if the user ties to "walk out of a RTB". Hope this makes sense.

    When debugging I noticed that in the RichTextBox.Document.CaretPosition there was a positionHandlerWalker.CanMoveUp and CanMoveDown property which kind of sounded what if am after, but it doesn't seem that the positionHandlerWalker property is available.

    Hope you can help

    /Terje
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 18 Feb 2013 Link to this post

    Hi Terje,

    What you can do is handle the PreviewEditorKeyDown event of your RadRichTextBox instances and check whether the caret should leave the rich text box. There are methods MoveDown() and MoveUp() of the caret which return a bool value showing whether the methods can be executed. You can handle the cases when navigating up/down/left/right is invoked and check whether they can be executed. 

    For example, this is how you should go about handling pressing the down arrow:
    void editro1_PreviewEditorKeyDown(object sender, Telerik.Windows.Documents.PreviewEditorKeyEventArgs e)
    {
        if (e.Key == Key.Down)
        {
            if (!editor1.Document.CaretPosition.MoveDown())
            {
                editor2.Focus();
            }
            else
            {
                e.SuppressDefaultAction = true;
            }
        }
    }

    I hope this information is helpful! Let us know if there is anything else we can assist you with.
     
    Regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top