locked
How to get correct ViewportTop of the text editor RRS feed

  • Question

  • I want to make a margin inside the text editor by using IWpfTextViewMargin.
    However, when I access the IWpfTextView.ViewportTop, it sometimes has negative value. How can I get the correct ViewportTop?

    By scrolling the vertical scrollbar inside the text editor, the wpf viewport which representing the text will be scrolled. The initial condition of the ViewportTop is 0.0 but sometimes, it will be negative. How can I get the pixels of actual scrolling distance of the viewport when vertical scrollbar is scrolled?

     

    msdn 论坛回复

    Friday, August 22, 2014 3:43 PM

Answers

  • Hi,

    I am using VS2013 with VsPackage project (also use MPF).

    Thanks for your reply, but I have solved my problem by using other methods and it now works.

    The original problem can be represented as below:

    Firstly, I manage line information in a manager class.

    Secondly, after each information updated or current IWpfTextViewMargin viewport's LayoutChanged, the margin control in the viewport should be painted asscioated with the line information.

    Thirdly, when painting wpf control in the custom IWpfTextViewMargin, I get line's y coordinate by using absolute pixel of each painting line which is simply line number* lineheight(usually 18 pixels per line). Then I want to get the actual vertical pixels change asscioated with the vertical scrollbar so that I can finally measure the relative pixels to the top edge of the viewport.

    The above method now has been changed by using the following code snapshot:

    ITextSnapshotLine line=  textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
    var wline = textView.TextViewLines.GetTextViewLineContainingBufferPosition(line.Start);
    if (wline!=null) return wline.Top; 

    the problem is that I can not get invisible IWpfTextViewLine which means I can only use visible line information or use other method to solve this.

     


    msdn 论坛回复

    • Marked as answer by 仲其刚 Friday, August 29, 2014 3:01 AM
    Monday, August 25, 2014 11:56 AM

All replies

  • Hi Vincky,

    Which VS version are you using? What kind of extension project type did you create?

    If you post your code here, it'll be easier for us to reproduce your problem and give you better help.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, August 25, 2014 11:22 AM
  • Hi,

    I am using VS2013 with VsPackage project (also use MPF).

    Thanks for your reply, but I have solved my problem by using other methods and it now works.

    The original problem can be represented as below:

    Firstly, I manage line information in a manager class.

    Secondly, after each information updated or current IWpfTextViewMargin viewport's LayoutChanged, the margin control in the viewport should be painted asscioated with the line information.

    Thirdly, when painting wpf control in the custom IWpfTextViewMargin, I get line's y coordinate by using absolute pixel of each painting line which is simply line number* lineheight(usually 18 pixels per line). Then I want to get the actual vertical pixels change asscioated with the vertical scrollbar so that I can finally measure the relative pixels to the top edge of the viewport.

    The above method now has been changed by using the following code snapshot:

    ITextSnapshotLine line=  textView.TextSnapshot.GetLineFromLineNumber(lineNumber);
    var wline = textView.TextViewLines.GetTextViewLineContainingBufferPosition(line.Start);
    if (wline!=null) return wline.Top; 

    the problem is that I can not get invisible IWpfTextViewLine which means I can only use visible line information or use other method to solve this.

     


    msdn 论坛回复

    • Marked as answer by 仲其刚 Friday, August 29, 2014 3:01 AM
    Monday, August 25, 2014 11:56 AM