Is there a text field that will auto size it's self to the content

Jesse Knott 686 Reputation points
2021-03-14T18:36:17.157+00:00

I need what would effectively be an Editor field that will resize it's self to the content within.

I have this code, but the problem seems that the editor field becomes oversized when large amounts of text is entered.

This is the code,

public EditorXF()
{
try
{
TextChanged += (sender, e) => InvalidateMeasure();
}
catch (Exception ex)
{
DebugTools.LogException(ex);
}
}

this code will modify the "Text Box", but like I said, if you enter large amounts of text, it will oversize it's self.
Here are some screen caps to demonstrate what I am talking about.

In the photos, I have simply highlighted the text in the "Output" and pasted it into the "Input" field

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,292 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,936 Reputation points
    2021-03-15T03:07:01.497+00:00

    but the problem seems that the editor field becomes oversized when large amounts of text is entered ... It seems that the text when copied and pasted in is doubling the pasted text in length.

    Hi, JesseKnott-2239. I created a basic demo to test entering text or pasting text, both work fine. The Editor class provides the AutoSize property which that controls whether the editor will change size to accommodate input as the user enters it. Try to set the property to TextChanges and test again.

       <Editor AutoSize="TextChanges"/>  
    

    Tutorial: https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.editorautosizeoption?view=xamarin-forms

    0 comments No comments