Hi,
I have an interesting issue with the selected text in my document within a RadRichTextBox.
I am handling the MouseLeftButtonUp event, and in it I want to do the following:
1. Select a specific section of the document
2. Substitute that text with other content from a pop-up window (user enters new text)
To do that, I use the following code to perform point 1:
document.Selection.Clear();
document.CaretPosition.MoveToInline(annotation);
document.CaretPosition.MoveToNext();
document.Selection.AddSelectionStart(document.CaretPosition);
document.CaretPosition.MoveToInline(annotation.End);
document.Selection.AddSelectionEnd(document.CaretPosition);
where 'document' is the RadRichTextBox.Document object, and 'annotation' is an AnnotationRangeStart object (never mind all this though, the issue is that I want to clear any previous selection in the document and create a new selection).
Then I do point 2 after my pop-up has been closed, simply by:
RadRichTextBox.Insert(newText);
All this works fine if there is no previous selection in the document, and the user simply clicks anywhere in the document: the MouseLeftButtonUp fires and I can do everything I intend to do as mentioned. HOWEVER, if instead of just clicking the user clicks+holds+selects some content in the document, when the MouseLeftButtonUp fires I get the following behavior:
- Even though when debugging it SEEMS like the document.Selection is actually clearing and changing when the code for point 1 executes, actually the UI still keeps the user selection (?). I can't find how/where those 2 different selections (user/UI created and the programmatically created) are stored, so as to really remove the user-created selection. So the problem is that, when I execute the code for point 2, is not really my programmatically created selection that gets substituted, but instead it's the user-created selection (not the intended behavior).
- I have tried to set to 'true' the Handled property of the MouseButtonEventArgs parameter on the MouseLeftButtonUp handler, so as to "invalidate" the creation of the UI selection... but instead of that, the behavior I get is that the MouseLeftButtonUp event is actually not finalized its handling so when I return to the RadRichTextBox the caret is in "selection mode" (hope I have explained this to make myselfunderstood :P). I've also tried to handle the MouseLeftButtonDown event instead, all to "avoid" the creation of the UI selection... but that doesn't work either (the behavior is even more strange).
Any help with this is much appreciated.
Cheers,
Juan
I have an interesting issue with the selected text in my document within a RadRichTextBox.
I am handling the MouseLeftButtonUp event, and in it I want to do the following:
1. Select a specific section of the document
2. Substitute that text with other content from a pop-up window (user enters new text)
To do that, I use the following code to perform point 1:
document.Selection.Clear();
document.CaretPosition.MoveToInline(annotation);
document.CaretPosition.MoveToNext();
document.Selection.AddSelectionStart(document.CaretPosition);
document.CaretPosition.MoveToInline(annotation.End);
document.Selection.AddSelectionEnd(document.CaretPosition);
where 'document' is the RadRichTextBox.Document object, and 'annotation' is an AnnotationRangeStart object (never mind all this though, the issue is that I want to clear any previous selection in the document and create a new selection).
Then I do point 2 after my pop-up has been closed, simply by:
RadRichTextBox.Insert(newText);
All this works fine if there is no previous selection in the document, and the user simply clicks anywhere in the document: the MouseLeftButtonUp fires and I can do everything I intend to do as mentioned. HOWEVER, if instead of just clicking the user clicks+holds+selects some content in the document, when the MouseLeftButtonUp fires I get the following behavior:
- Even though when debugging it SEEMS like the document.Selection is actually clearing and changing when the code for point 1 executes, actually the UI still keeps the user selection (?). I can't find how/where those 2 different selections (user/UI created and the programmatically created) are stored, so as to really remove the user-created selection. So the problem is that, when I execute the code for point 2, is not really my programmatically created selection that gets substituted, but instead it's the user-created selection (not the intended behavior).
- I have tried to set to 'true' the Handled property of the MouseButtonEventArgs parameter on the MouseLeftButtonUp handler, so as to "invalidate" the creation of the UI selection... but instead of that, the behavior I get is that the MouseLeftButtonUp event is actually not finalized its handling so when I return to the RadRichTextBox the caret is in "selection mode" (hope I have explained this to make myselfunderstood :P). I've also tried to handle the MouseLeftButtonDown event instead, all to "avoid" the creation of the UI selection... but that doesn't work either (the behavior is even more strange).
Any help with this is much appreciated.
Cheers,
Juan