Search code examples
xamarinxamarin.formseditorscrollviewcontentoffset

How to identify user tapped on Editor field in Xamarin forms?


First thing, I have an Editor.I can Identify if the user entered any text in that Edior.But i need to return something when the user tapped on the Editor. How to achieve this?

        var msgEditor = new Editor
        {
            Margin = new Thickness(10, 0, 10, 0),
            HeightRequest = App.ScreenHeight,
        };

Secong thing, Editor is inside the scrollview.When i tapped on the Editor scrollview scrolls down.I need to manually pull down to see the cursor.How to set content offset when i tapped on Editor?

  ScrollView scroll = new ScrollView

  {
      Content = msgEditor,
  };
  Content = scroll;

Solution

  • On the editor, you have the focus event that notifies you that the user tapped the editor. You can do as follow :

    {
        var editor = new Editor();
        editor.Focused += EditorOnFocused;
    }
    
    private void EditorOnFocused(object sender, FocusEventArgs focusEventArgs)
    {
        //do your stuff
    }