0
votes

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
you can find solution with customization for more details check this link-developer.xamarin.com/guides/xamarin-forms/… - Pratius Dubey
I know about renderers, but I don't know how specifically to enable the resizing option in editor using the renderers, meaning I don't know what code to write inside the renderer. - JackPot16
Ok, we can take help form XLap control here is github URL-github.com/XLabs/Xamarin-Forms-Labs/wiki/ExtendedEntry - Pratius Dubey
"I found this partial solution, it kind of works fine but it is not so natural(as for example EditText in Android).", why you think it's not so natural? Your code works fine. - Grace Feng
It works better but not perfect. For example, when I press enter I might see only half of the previous line(the bottom half). I'll add pics to ilustrate. - JackPot16

1 Answers

0
votes

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.