Compare GetNextInsertionPosition and GetNextContextPosition in WPF

Posted by paradisonoir on Stack Overflow See other posts from Stack Overflow or by paradisonoir
Published on 2010-03-30T19:00:58Z Indexed on 2010/03/30 19:03 UTC
Read the original article Hit count: 322

Filed under:
|
|
|

As I enter a character in my RichTextBox, I want to get the next character from the its TextRange.

So here is how I do it:

TextPointer ptr1= RichTextBox.CaretPosition;
char nextChar = GetNextChar();
while (char.IsWhiteSpace(nextChar))
{
   ptr1= ptr1.GetNextInsertionPosition(LogicalDirection.Forward);
   nextChar = GetCharacterAt(Ptr1);
}

then I get the ptr1 of the next character and from the TextPointer, I get the TextRange, and do my changes.

So here is the problem?

when the next word is spelled correctly, I have no problem, but if it's not spelled properly then ptr1 would not point to the first character of the next word (the second character), and if I use GetNextContextPosition(LogicalDirection.Forward) it would give me the first letter of the next word if it's misspelled. So depending on the spelling only one of them works?

I was just wondering if you have any idea about this problem? Is there anything wrong I am doing here?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#