WPF: richtextbox tab issue
I am really confused at what is going on here. I have a rtb, and I have allowTab set to true, so the user can indent.
The problem is, there seems to be no tab character infront of the text. For example, if I have text that looks like:
this is some text
and some more text
and one more line
I would imagine, if I looked at the text in code, that it would look like:
this is some text \r\n\tand some more text\r\n\tand one more line
but instead it just looks like:
this is some text \r\nand some more text\r\nand one more line (notice there are
no tabs)
The tabs are very important to me, as I need to keep track of "hierarchy" of lines, I need to know how much space is before lines. (either spaces or tabs开发者_开发问答 (\t)). Is there a way I can see the tab space as \t's when I look at the string in code?
Should I just catch the key down event, and replace the tab key event with spaces? thats how I did it in a winforms project, but i figure WPF will have some neat way to handle it :)
Thanks!
Edit when I hit the tab button, does it change the paragraph textindent? aka, there is no noticeable difference in the text itself?
I am not sure how are you getting the text back but it should work, test:
string text = "this is some text \r\n\tand some more text\r\n\tand one more line";
richTextBox1.AppendText(text);
text = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;
//text will be the same: "this is some text \r\n\tand some more text\r\n\tand one more line\r\n"
精彩评论