C# WPF:richtextbox选项卡问题
我真的对这里发生的事情感到困惑。我有一个rtb,我已经将allowTab设置为true,所以用户可以缩进 问题是,文本前面似乎没有制表符。例如,如果我有如下文本:C# WPF:richtextbox选项卡问题,c#,wpf,flowdocument,C#,Wpf,Flowdocument,我真的对这里发生的事情感到困惑。我有一个rtb,我已经将allowTab设置为true,所以用户可以缩进 问题是,文本前面似乎没有制表符。例如,如果我有如下文本: this is some text and some more text and one more line this is some text \r\nand some more text\r\nand one more line (notice there are no tabs) 我会想象,如果我看代码中的
this is some text
and some more text
and one more line
this is some text \r\nand some more text\r\nand one more line (notice there are
no tabs)
我会想象,如果我看代码中的文本,它会像:
this is some text \r\n\tand some more text\r\n\tand one more line
但事实上,它看起来就像:
this is some text
and some more text
and one more line
this is some text \r\nand some more text\r\nand one more line (notice there are
no tabs)
标签对我来说非常重要,因为我需要跟踪行的“层次结构”,我需要知道行之前有多少空间。(空格或制表符(\t))。当我查看代码中的字符串时,是否有一种方法可以将选项卡空间视为\t
我是否应该捕获key down事件,并用空格替换tab键事件?我在winforms项目中就是这样做的,但我认为WPF将有一些巧妙的方法来处理它:)
谢谢
编辑当我点击tab按钮时,是否会更改段落文本缩进?aka,文本本身没有明显的差异?我不确定您是如何取回文本的,但它应该可以工作,测试:
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"
好的,然后您必须检查每个块的
textdindent
,例如:(richTextBox1.Document.Blocks.FirstBlock)).ContentStart.paragration.textdindent