Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.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# wpf richtextbox BringIntoView使用TextRange.ClearAllProperties不工作?_C#_Wpf_Scroll_Richtextbox - Fatal编程技术网

C# wpf richtextbox BringIntoView使用TextRange.ClearAllProperties不工作?

C# wpf richtextbox BringIntoView使用TextRange.ClearAllProperties不工作?,c#,wpf,scroll,richtextbox,C#,Wpf,Scroll,Richtextbox,我用wpf编程。当突出显示的单词从viewportHeight移动时,我必须向上滚动一页。所以我使用下面的代码。它工作正常 FrameworkContentElement fce = (textRange.Start.Parent as FrameworkContentElement); if (fce != null) { fce.BringIntoView(); } 但之后我需要使用下面

我用wpf编程。当突出显示的单词从viewportHeight移动时,我必须向上滚动一页。所以我使用下面的代码。它工作正常

FrameworkContentElement fce = (textRange.Start.Parent as FrameworkContentElement);
            if (fce != null)
            {
                fce.BringIntoView();
            }
但之后我需要使用下面的代码来突出显示单词

   TextRange fullRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
                fullRange.ClearAllProperties(); 
                TextPointer start = fullRange.Start.GetPositionAtOffset(offset);
                TextPointer end = start.GetPositionAtOffset(length);
                TextRange textRange = rtb.Selection;
                textRange.Select(start, end);
textRange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(m_DehighlightbackgroundColor));
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(m_DehighlightforegroundColor));
在我使用
fullRange.ClearAllProperties()之后
fce.BringIntoView()不工作。我的意思是不滚动到突出显示的单词

那么,如何解决这个问题呢

问候
阿琼这个回答为我解决了一个类似的问题:

richtextbox将子对象放入视图中

总而言之,请尝试将以下内容放在BringIntoView之前:

Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,新操作(委托{}))