'Xamarin Forms Editor Scrollbar

I have a need for an Editor, with a checkbox in a left margin for each line.

(When the user clicks on the check box, the text for that line changes color.)

At the moment I can create the check boxes dynamically in a grid when newlines are added to the editor.

However once the editor scrolls, I have no way to sync the scrolling for the check box grid as I don't have access to the behavior or events of the editor scrollbar.

Two questions:

  • Any way I can access that scrollbar?
  • Any way I can change the font color upon a check box click

UPDATE:

I've decided to draw the checkboxes on the editor renderer's OnDraw instead, as per this: How to show line number in EditText

Then I will handle Touch events on the editor to turn the checks on and off. However my problem now is that the checkboxes drawn on the canvas don't scroll with the editor's text, so I'm stuck again.

Any ideas?



Solution 1:[1]

PROBLEM SOLVED

Below is the solution I had with the drawn text not scrolling.

My mistaken assumption was that text drawn 'offscreen' would automatically scroll into view with scrolling actions.

It appears however that the drawing is done only in relation to the visible size of the editor, not the virtual size.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int baseline = getBaseline();
    for (int i = 0; i < getLineCount(); i++) {

        //problem line
        //canvas.drawText("" + (i+1), rect.left, baseline, paint);

        //PROBLEM RESOLVED WITH
        canvas.drawText("" + (i+1), rect.left, baseline - ScrollY, paint);

        baseline += getLineHeight();
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jho