Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public class CustomEditorRenderer : EditorRenderer
  2. {
  3. private const int InitialNumberLine = 4;
  4. private double _height;
  5. private double _lineHeight;
  6. private int _lastNumerOfLines;
  7. protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
  8. {
  9. base.OnElementChanged(e);
  10. if (Control == null) return;
  11. Control.ScrollChange += Control_ScrollChange;
  12. Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
  13. Control.SetLines(InitialNumberLine);
  14. _lastNumerOfLines = InitialNumberLine;
  15. }
  16.  
  17. protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
  18. {
  19. base.OnElementPropertyChanged(sender, e);
  20.  
  21. if (Control.LineCount < _lastNumerOfLines && _lastNumerOfLines > InitialNumberLine)
  22. {
  23. ((CustomEditor)sender).HeightRequest = ((CustomEditor)sender).Height - _lineHeight / 2;
  24. }
  25.  
  26. if (_height != 0)
  27. {
  28. Control.SetLines(Control.LineCount + 1);
  29. ((CustomEditor) sender).HeightRequest = ((CustomEditor) sender).Height + _height / 4;
  30. _height = 0;
  31. }
  32. _lastNumerOfLines = Control.LineCount;
  33. }
  34.  
  35. private void Control_ScrollChange(object sender, ScrollChangeEventArgs e)
  36. {
  37. if (Control.ScrollY == 0) return;
  38. _height = Control.ScrollY;
  39. Control.ScrollY = 0;
  40. if (_lineHeight == 0) _lineHeight = _height;
  41.  
  42. //if(Control.Text[Control.Text.Length-1] != ' ') Control.Append(" ");
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement