Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin forms Editor AutoSize does not work

Im I just misunderstanding the name "AutoSize"-property on the Editor-control or does it simply not work?

I have a control like this in xaml:

<Editor AutoSize="TextChanges" HeightRequest="100"/>

It comes out fine at height 100, but when I have written a few rows it does not change size/height. The upper text is simply scrolled up.

like image 770
Cowborg Avatar asked Oct 25 '18 08:10

Cowborg


2 Answers

Cause:

An Editor will not auto-size if the HeightRequest property has been set.

You can refer to :

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/editor#auto-sizing-an-editor

Solution:

You can remove the HeightRequest property.And the Editor will automatically grows when you continue typing additional rows.

<Editor Text="Enter text here" AutoSize="TextChanges" />
like image 109
nevermore Avatar answered Oct 12 '22 13:10

nevermore


In case you want AutoSize to work and at the same time to have height of 100, you can do something like this:create a new class that inherits Editor, override method below and use a new class instead on your page

protected override SizeRequest OnMeasure(double widthConstraint, double heightConstraint)
{
     var sizeRequest = base.OnMeasure(widthConstraint, heightConstraint);

     return new SizeRequest(new Size(sizeRequest.Request.Width, Math.Max(100, sizeRequest.Request.Height)));
}
like image 33
Vorotnyak_Nazar Avatar answered Oct 12 '22 14:10

Vorotnyak_Nazar