C# wpf richtextbox BringIntoView使用TextRange.ClearAllProperties不工作?
我用wpf编程。当突出显示的单词从viewportHeight移动时,我必须向上滚动一页。所以我使用下面的代码。它工作正常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(); } 但之后我需要使用下面
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,新操作(委托{}))代码>