简体   繁体   中英

Create a size changing Editor in Xamarin

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:

第一行文字

pressing enter:

文字第二行

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

Android

In android it actually works great:

在此处输入图片说明

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM