0

I navigate focus from an Entry to another Entry inside a AbsoluteLayout through a button click.

On every focus navigation the keyboard hide and again comes back to visiblity. I want the Keyboard to avoid hiding if the Next child to be focused is an Entry.

Xaml code

<Grid>
    <ScrollView>
        <local:CustomLayout
            x:Name="entryStack"
            BindableLayout.ItemsSource="{Binding SomeItems}">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <Entry
                        WidthRequest="100"
                        Focused="Entry_Focused"/>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </local:CustomLayout>
    </ScrollView>
    <Button VerticalOptions="Start" HorizontalOptions="End" Text="NextField" Clicked="Button_Clicked"/>
</Grid>

CustomLayout inheriting AbsoluteLayout

public class CustomLayout : AbsoluteLayout
{
    public CustomLayout()
    {
    }

    protected override void OnChildAdded(Element child)
    {
        base.OnChildAdded(child);
        var childElement = (child as View);
        var index = this.Children.IndexOf(childElement);
        childElement.TranslationY = index * 30;
    }
}

Xaml.cs

public partial class MainPage : ContentPage
{
    public List<string> SomeItems { get; set; }
    int i = 0;
    public MainPage()
    {
        InitializeComponent();
        this.SomeItems = new List<string>()
        {
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
            "One",
        };

        this.BindingContext = this;
    }

    void Button_Clicked(System.Object sender, System.EventArgs e)
    {
        i = i+1;
        (entryStack.Children[i] as Entry).Focus();
    }

    void Entry_Focused(System.Object sender, Xamarin.Forms.FocusEventArgs e)
    {
        i = entryStack.Children.IndexOf((sender as Entry));
    }
}

enter image description here

Is this possible to achieve. Am I doing something wrong here??

6
  • Did you try this? stackoverflow.com/a/42384926/4550227
    – Ganesan VG
    Mar 4, 2020 at 6:32
  • No @GanesanVG, I'll try now. Mar 4, 2020 at 6:37
  • I tried it now, @GanesanVG. The code was not meant to keep the Keyboard open but to show the Keyboard. What I need is to avoid the closing of Keyboard while next Entry is focused Mar 4, 2020 at 7:15
  • I think you need to do something in the custom renderer and have a look at comments in this thread may give you some idea. I will update you if I find a solution.
    – nevermore
    Mar 4, 2020 at 8:51
  • Thanks @JackHua-MSFT. Will check the thread. Mar 4, 2020 at 8:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.