Xamarin Forms Editor Control – How to Change the Height Dynamically ?
When I was trying to create a UI with a multi-line editor control in Xamarin Forms, I got an issue that It does not extend its height when I was adding multiple lines like in Android message app, Whatsapp etc..
His is my first XAML code which I tried before solve the issue.
In this UI, you can see that is does not extend its height when enter multiple lines.
Here is the code before customizing the editor.
Then I looked for a solution for how to do it..
The solution is adding a custom render. Inside the custom render, we have to call InvalidateMeasure() method inside the TextChanged event to invalidate the layout of this Xamarin.Forms.VisualElement.
Thanks @JulianPasquefor the solution.
How to add the custom render for the Editor in the app.
First I’ll create a class EditorXF inside the CustomRenderer folder. and inherit Xamarin.Forms.Editor class to the EditorXF.
Then create a constructor for EditorXF and create an event for TextChanged and call InvalidateMeasure() inside the event.
Then what we have to do is, call the customized render in the XAML code of the View.
First we have to add the namespace of the EditorXF render in the XAML Vew.
Then Change the replace the Editor control by EditorXF render control using local:EditorXF tag.
Then run the app and we will be able to add multiple lines and extend the height of the editor control dynamically.
You can Have the full solution here @GitHub ..