Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CustomEditorRenderer : EditorRenderer
- {
- private const int InitialNumberLine = 4;
- private double _height;
- private double _lineHeight;
- private int _lastNumerOfLines;
- protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
- {
- base.OnElementChanged(e);
- if (Control == null) return;
- Control.ScrollChange += Control_ScrollChange;
- Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
- Control.SetLines(InitialNumberLine);
- _lastNumerOfLines = InitialNumberLine;
- }
- protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
- {
- base.OnElementPropertyChanged(sender, e);
- if (Control.LineCount < _lastNumerOfLines && _lastNumerOfLines > InitialNumberLine)
- {
- ((CustomEditor)sender).HeightRequest = ((CustomEditor)sender).Height - _lineHeight / 2;
- }
- if (_height != 0)
- {
- Control.SetLines(Control.LineCount + 1);
- ((CustomEditor) sender).HeightRequest = ((CustomEditor) sender).Height + _height / 4;
- _height = 0;
- }
- _lastNumerOfLines = Control.LineCount;
- }
- private void Control_ScrollChange(object sender, ScrollChangeEventArgs e)
- {
- if (Control.ScrollY == 0) return;
- _height = Control.ScrollY;
- Control.ScrollY = 0;
- if (_lineHeight == 0) _lineHeight = _height;
- //if(Control.Text[Control.Text.Length-1] != ' ') Control.Append(" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement