in a RichTextBox, how can I get the Run which a TextPointer is pointing at? And how get the character position in the Run of the TextPointer?
View Complete Post
MSDN Magazine May 2004
How to get the number of the line, which is under the cursor in RichTextBox control.
1. Create RichTextBox control and type some text inside
2. Draw anything e.g. in the Paint
3. Copy some part of image to the clipboard
4. Paste it into the RTB (it appears correctly, all seems to be good)
5. Save contents with:
MemoryStream Src = new MemoryStream();
new TextRange(RTB.Document.ContentStart, RTB.Document.ContentEnd).Save(Src, System.Windows.DataFormats.Rtf);
6. Load it using:
new TextRange(RTB.Document.ContentStart, RTB.Document.ContentEnd).Load(Src, System.Windows.DataFormats.Rtf);
7. Image is lost while text is still present.
The same story is with DataFormats.Xaml at least.
Can anybody say how to save RTF with image from WPF RTB? Thanx in advance.
I would like to return the TextPointer to an arbitrary (nth) character position (including whitespace) of RichTextBox XAML. ÃÂ Example:
Given "Mary had a little lamb".ÃÂ I would like to return a text pointer corresponding to the letter position 8, (in this case, I would get a TextPointer for the insertion point just before the letter 'd' in 'had'). This would need to ignore any formatting elements and other UI elements in the xml anywhere in the text.
ÃÂ I think this would be similar to the method
but which ignores all symbols other than character data (recalling that GetPositionAtOffset includes all "symbols", not only text).
ÃÂ Performance: I realize that I could write a function which moves a TextPointer one position at a time and inspects what type of symbol is found at each spot and stops when it gets to the Nth character. But that seems very expensive. I am hoping there is a built in function which is more performant. (and I would really have thought this might be part of the System.Windows.DocumentsÃÂ API)
ÃÂ thanks very much.
for me this seems like a BUG.
You can download a sample project VS 2010 here: http://www.sendspace.com/file/xtn1mc
- When you click from the left Content Cell to the right Homework cell staying on the SAME ROW => LostFocus does not work!
- When you click from the left Content Cell to the right Homework cell of ANOTHER ROW => LostFocus works!
- Clicking on all 4 cells from the Content immediately raises a property changed event.
And now the CRAZY stuff...:
- Clicking on all 4 cells from the Homework column starting for example at the first cell entering "test" clicking in 2nd cell entering "test" clicking in 3rd cell entering "test" clicking in 4th cell entering "test" NOTHING happend.
When I go now the same way in reverse order from cell 4 to cell 1 sometimes I get property changes ROFL ...
Can you explain that?
- The Content Column is a DataGridTextColumnT
- The Homework Column is a DataGridTemplateColumn with your DataTemplated RichTextBox.
The RichTextBox I use is from the Extended W