Clear pageup/pagedown panning values after clear and reload content in wpf richtextbox?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 10:24:26

问题


i am working in wpf richtextbox.use the below function use for page up.

TextRange range10 = new TextRange(txtAppendValue.CaretPosition.GetLineStartPosition(1), txtptrCaret);

                FrameworkContentElement fce1 = (range10.End.Parent as FrameworkContentElement);
                if (fce1 != null)
                {
                    fce1.BringIntoView();
                    range10 = null;
                    fce1 = null;
                }

its working.After i clear the richtextbox and load some other content,at that time the content shown where the pageup happened in last time?how to clear when i reload the document.

Updated:

public void HideTopBorder()
        {
            TextPointer currentline = txtAppendValue.CaretPosition.GetLineStartPosition(1);
            System.Windows.Rect rc = currentline.GetCharacterRect(LogicalDirection.Forward);
            System.Windows.Point upperLeftCorner = rc.Location;
            HitTestResult result = VisualTreeHelper.HitTest(txtAppendValue, upperLeftCorner);
            if (result == null)
            {

                Thickness margin = txtAppendValue.Margin;
                margin.Top = -20;
                txtAppendValue.Margin = margin;
                currentline = null;
            }
            else
            {
                currentline = null;
            }

        }

After the result null only pageup happened.at that time i clear the document and load an another document.But now show the richtextbox where the already panned point.not top of the document.

Regards Arjun


回答1:


Before you load a new document save the value of rtb.VerticalOffset. Then load the new document and reassign the stored value to rtb.VerticalOffset.



来源:https://stackoverflow.com/questions/34783272/clear-pageup-pagedown-panning-values-after-clear-and-reload-content-in-wpf-richt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!