Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么';与RichTextBox一起使用时,使用ApplyPropertyValue()更新_C#_Wpf_.net 4.0 - Fatal编程技术网

C# 什么';与RichTextBox一起使用时,使用ApplyPropertyValue()更新

C# 什么';与RichTextBox一起使用时,使用ApplyPropertyValue()更新,c#,wpf,.net-4.0,C#,Wpf,.net 4.0,显然,当我在RichTextBox上使用函数ApplyPropertyValue()时,选择将停止正常工作。 我有一个RichTextBox,里面装满了一些文本 string selectText(int index, int length) { TextRange textRange = new TextRange(TB.Document.ContentStart, TB.Document.ContentEnd); if (tex

显然,当我在
RichTextBox
上使用函数
ApplyPropertyValue()
时,
选择将停止正常工作。
我有一个RichTextBox,里面装满了一些文本

string selectText(int index, int length)
        {
            TextRange textRange = new TextRange(TB.Document.ContentStart, TB.Document.ContentEnd);
            if (textRange.Text.Length >= (index + length))
            {
                TextPointer start = textRange.Start.GetPositionAtOffset(index, LogicalDirection.Forward);
                TextPointer end = textRange.Start.GetPositionAtOffset(index + length, LogicalDirection.Backward);
                TB.Selection.Select(start, end);
                return TB.Selection.Text;
            }
            return null;
        }
display.Text = selectText(6, 8);
// display contains the string "arranged"
TB.Selection.ApplyPropertyValue(RichTextBox.ForegroundProperty, "Red");
// display now contains the string "arrang" (should be "arranged")
display.Text = selectText(6, 8);
display
是一个文本块,用于显示用于调试的变量值,
TB
是一个RichTextBox

selectText(i,length)
如果在不使用ApplyPropertyValue()的情况下使用,则该函数可以正常工作,并始终在
TB
中返回正确的文本子字符串

执行上述代码后,
display
包含“arrang”而不是“arrang”。另外,如果删除ApplyPropertyValue()语句,
display
将按预期包含“arranged”

ApplyPropertyValue()是怎么回事?我是不是遗漏了什么