Reacting to changed postion in table on RadRichTextBox

7 posts, 1 answers
  1. Lasse
    Lasse avatar
    10 posts
    Member since:
    Jul 2013

    Posted 10 Jun 2014 Link to this post

    I'd like to react when a user changes the carret postion to a new cell inside a table.

    I have tried hooking up to the Document.CaretPosition.PositionChanged event. But the event doesn't seem to fire as expected. It only fires once, when the RadRichTextBox in instantiated.

    Any suggestion as to how handle this?
  2. Answer
    Kammen
    Admin
    Kammen avatar
    312 posts

    Posted 13 Jun 2014 Link to this post

    Hello Lasse,

    Using the PositionChanged event is the right thing to do in your case. However, note that this event is in the RadDocument, so when the document is changed, you should add a handler to the new document's CaretPosition as well.

    The code below shows how to attach to the PositionChanged event.

    private void radRichTextBox_Loaded(object sender, RoutedEventArgs e)
    {
        this.radRichTextBox.Document.CaretPosition.PositionChanged += this.CaretPosition_PositionChanged;
    }
     
    private void radRichTextBox_DocumentChanging(object sender, EventArgs e)
    {
        if (this.radRichTextBox.Document != null)
        {
            this.radRichTextBox.Document.CaretPosition.PositionChanged -= this.CaretPosition_PositionChanged;
        }
    }
     
    private void radRichTextBox_DocumentChanged(object sender, EventArgs e)
    {
        this.radRichTextBox.Document.CaretPosition.PositionChanged += CaretPosition_PositionChanged;
    }
     
    private void CaretPosition_PositionChanged(object sender, EventArgs e)
    {
    }

    If you have further questions do not hesitate to contact us.

    Regards,
    Kammen
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Lasse
    Lasse avatar
    10 posts
    Member since:
    Jul 2013

    Posted 18 Jun 2014 Link to this post

    Turned out this was exactly my problem. The Document is new'ed each time the formatter sets in.
    Thank you!
  5. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 19 Aug 2014 in reply to Kammen Link to this post

    Hi Kammen, 

    I am facing similar issue, I couldn't get the CaretPosition.PositionChanging event fired when I am inside the Header document. 

    I tried your above post and tried below as well.
    _richTextBox.ActiveDocumentEditorChanged += _richTextBox_ActiveDocumentEditorChanged;

     void _richTextBox_ActiveDocumentEditorChanged(object sender, Telerik.Windows.Documents.UI.ActiveDocumentEditorChangedEventArgs e)
            {
                if (e.DocumentEditorType == DocumentEditorType.Header)
                {
                    _richTextBox.ActiveDocumentEditor.Document.CaretPosition.LocationChanged += CaretPosition_LocationChanged;
                    _richTextBox.ActiveDocumentEditor.Document.CaretPosition.PositionChanging += HeaderPositionChanged;
                }
            }
    But it doesnt work. I never see the PositionChanging event firing when I am in Header. But it works when I am in the main document. 

    Could you help me in this issue please ?

    Thanks
    Anand


  6. Petya
    Admin
    Petya avatar
    975 posts

    Posted 22 Aug 2014 Link to this post

    Hi Anand,

    Could you please share what is the end goal you are trying to achieve? The approach mentioned in Kammen's reply is handy when you want to subscribe to the main document of each newly loaded document in the control. However, in the case of headers and footers this is not that straightforward, as there are cases when the document in them is not yet initialized when you change the active editor. Further, there is no event that is raised when the active editor is changing, so there is no appropriate place to unsubscribe from the previous document.

    With this in mind, please share what are the requirements in your case and I will do my best to provide an appropriate for your scenario advice.

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  7. Anand
    Anand avatar
    30 posts
    Member since:
    Jul 2014

    Posted 22 Aug 2014 in reply to Petya Link to this post

    Hi Petya,

    Thanks for the reply. Here is what, I am trying to achieve. 

    We add custom annotations in the Header. We need to add a functionality to remove the as well. So we need to track the mouse pointer, 
    when the user is clicking around the Header. So I would like to hook up to the Header's CaretPosition.PositionChanging event, and pick the custom annotation based on the Header Cursor pointer and remove them. 

    Would appreciate , if you help me to address this issue

    Regards
    Anand



  8. Petya
    Admin
    Petya avatar
    975 posts

    Posted 27 Aug 2014 Link to this post

    Hello Anand,

    Thank you for the additional information.

    I am still a bit confused on the end result you are trying to achieve. Do you want to remove an annotation when the caret is positioned in it, i.e. if the user clicks in the annotation range?

    Generally, if you are creating a command or conditioning your removal logic on the caret position, subscribing to the PositionChanged event of any of the documents (main or header/footer) would not be needed. Basically, at any point you can determine whether the caret is in an annotation through the active document editor. What is more, the position/location of the caret changes excessively when editing or navigating a document, so this might cause performance issues in your application.

    If this is not the case and I misunderstood you, please open a support ticket and provide more details on your scenario there. 

    Regards,
    Petya
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WPF is Visual Studio 2017 Ready