[英]wpf richtextbox BringIntoView Not working using TextRange.ClearAllProperties?
i am programming in wpf.i have to scroll one page up when highlighted word move from viewportHeight.So i am using the below code.it works fine. 我正在wpf中编程。当突出显示的单词从viewportHeight中移出时,我必须向上滚动一页。所以我正在使用下面的代码。它工作正常。
FrameworkContentElement fce = (textRange.Start.Parent as FrameworkContentElement);
if (fce != null)
{
fce.BringIntoView();
}
But after i need to use the below code for highlight word. 但是之后,我需要使用以下代码突出显示单词。
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));
After i used fullRange.ClearAllProperties();
在我使用
fullRange.ClearAllProperties();
the fce.BringIntoView();
fce.BringIntoView();
not working.I mean not scroll to highlighted word. 不起作用。我的意思是不滚动到突出显示的单词。
So,how to solve this issue? 那么,如何解决这个问题呢?
Regards Arjun 问候阿琼
This answer solved a similar issue for me: 这个答案为我解决了一个类似的问题:
How to bring Inline from a RichTextBox Child into View richtextbox-child-into-view 如何将内联从RichTextBox子级带入视图 richtextbox-child-into-view
To summarise, try putting the following before BringIntoView: 总而言之,请尝试将以下内容放在BringIntoView之前:
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { }));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.