wpf richtextbox BringIntoView 使用 TextRange.ClearAllProperties 不工作?
wpf richtextbox BringIntoView Not working using TextRange.ClearAllProperties?
我正在编程 wpf.i 当突出显示的单词从 viewportHeight.So 移动时必须向上滚动一页我正在使用下面的 code.it 工作正常。
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();
不是 working.I 意味着不滚动到突出显示的单词。
那么,如何解决这个问题?
问候
阿俊
这个答案为我解决了类似的问题:
How to bring Inline from a RichTextBox Child into View
richtextbox-child-into-view
总结一下,尝试将以下内容放在 BringIntoView 之前:
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { }));
我正在编程 wpf.i 当突出显示的单词从 viewportHeight.So 移动时必须向上滚动一页我正在使用下面的 code.it 工作正常。
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();
不是 working.I 意味着不滚动到突出显示的单词。
那么,如何解决这个问题?
问候 阿俊
这个答案为我解决了类似的问题:
How to bring Inline from a RichTextBox Child into View richtextbox-child-into-view
总结一下,尝试将以下内容放在 BringIntoView 之前:
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { }));