This is a migrated thread and some comments may be shown as answers.

Reacting to changed postion in table on RadRichTextBox

6 Answers 123 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Lasse
Top achievements
Rank 1
Lasse asked on 10 Jun 2014, 06:17 PM
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?

6 Answers, 1 is accepted

Sort by
0
Accepted
Kammen
Telerik team
answered on 13 Jun 2014, 02:51 PM
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.
 
0
Lasse
Top achievements
Rank 1
answered on 18 Jun 2014, 11:22 AM
Turned out this was exactly my problem. The Document is new'ed each time the formatter sets in.
Thank you!
0
Anand
Top achievements
Rank 1
answered on 19 Aug 2014, 08:59 AM
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


0
Petya
Telerik team
answered on 22 Aug 2014, 07:55 AM
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.
 
0
Anand
Top achievements
Rank 1
answered on 22 Aug 2014, 09:02 AM
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



0
Petya
Telerik team
answered on 27 Aug 2014, 10:54 AM
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.
 
Tags
RichTextBox
Asked by
Lasse
Top achievements
Rank 1
Answers by
Kammen
Telerik team
Lasse
Top achievements
Rank 1
Anand
Top achievements
Rank 1
Petya
Telerik team
Share this question
or