Create a size changing Editor in Xamarin

740 Views Asked by At

I want to create a Xamarin Forms Editor Control that changes its height when it gets filled(Adds a new line when space in previous line finished). I'm only interested in WinPhone and Android Platfroms.

The Editor itself doesn't support such property.

I know that the Android native control (EditText) supports it (Not sure about the WinPhone variant, TextBox). But I'm not sure how to implement it.

It will be very helpful if someone can explain me how to create the renderers for these platforms.

Edit

I found this partial solution, it kind of works fine but it is not so natural(as for example EditText in Android).

class RoundedEditor : Editor
{
    public RoundedEditor()
    {
        this.TextChanged += (sender, e) => { this.InvalidateMeasure(); };
    }
}

I'll be glad if someone will provide a better solution.

Edit 2

Here are the results of how it works now:

UWP

Writing first line:

First line of text

pressing enter:

Second line of text

The previous line is not showed completely as I would like.

Android

In android it actually works great:

enter image description here

enter image description here

1

There are 1 best solutions below

2
On

You will have to implement a custom Android EditText, and then use it for your XamarinForms control (by implementing a custom renderer for it)

Take a look at this implementation of resizable EditText: https://github.com/ViksaaSkool/AutoFitEditText

You'd have to translate it to C# obviously, but its a great start point.