简体   繁体   English

Xamarin 表单编辑器滚动条

[英]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我决定改为在编辑器渲染器的 OnDraw 上绘制复选框,如下所示: 如何在 EditText 中显示行号

Then I will handle Touch events on the editor to turn the checks on and off.然后我将在编辑器上处理 Touch 事件以打开和关闭检查。 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?有任何想法吗?

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();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM