0
votes

I am using a grid in Xamain forms and I want on the selection event to call the keyboard I thought doing this word wok.

I am using the plugin dialogue kit to display a numeric entry but my quesiton is the keyboard is only displaying on the text box when it has focus how Do I force the keyboard to come up so the user does not have to click into the field.

 new Entry()
 {
                Keyboard = Keyboard.Numeric
 };

 var resultQty = await Plugin.DialogKit.CrossDiaglogKit.Current.GetInputTextAsync("Test", $"Please goto Bin {item.BinName} , and enter the visible stock of the item." + item.Name, null, Keyboard.Numeric);

The code from Dialog kit shows that it attempts to place a focus on the entry field.

<ContentView.Content>
    <StackLayout Padding="10" BackgroundColor="White" VerticalOptions="CenterAndExpand" Margin="25">
        <Label FontAttributes="Bold" FontSize="Large" Text="{Binding Title}"/>
        <Label FontSize="Large" Text="{Binding Message}"/>
        <Entry x:Name="txtInput" Keyboard="{Binding Keyboard}"/>
        <StackLayout Margin="10" Orientation="Horizontal">
            <Button Text="{Binding OK}" Clicked="Confirm_Clicked" HorizontalOptions="FillAndExpand"/>
            <Button Text="{Binding Cancel}" Clicked="Cancel_Clicked" HorizontalOptions="FillAndExpand"/>
        </StackLayout>
    </StackLayout>
</ContentView.Content>

You will see here that the dialog kit calls the above few as such

public Task<string> GetInputTextAsync(string title, string message,string currentText = null, Keyboard keyboard = null)
{           
        if (keyboard == null) keyboard = Keyboard.Default;
        var cts = new TaskCompletionSource<string>();
        var _dialogView = new Plugin.DialogKit.Views.InputView(title, message,currentText,keyboard);
        _dialogView.FocusEntry();
        _dialogView.Picked += (s, o) => { cts.SetResult(o); PopupNavigation.PopAsync(); };
        PopupNavigation.PushAsync(new PopupPage { Content = _dialogView });
        return cts.Task;
  }

Which as you can see is calling the but i think the placement of this is wrong as its before its pops onto the view.

public void FocusEntry() { txtInput.Focus(); }

1
just call the entry's Focus eventJason
@Jason the entry is inside the Plugin Dialog Kit i dont have control over that other than telling it to display the numeric text box.csharpdudeni77
@Jason I tried to make it popup but it still did not work the entry field is within rg popups.csharpdudeni77
@Jason plesae see my above edits.csharpdudeni77
@rogue39nin given that this is an external library you could either: create a pull request with the changes and hope the maintainer respond "quickly", or you can do the PR but at the same time fork the project and do the changes and use a dll until the PR is merged and your change becomes part of the original repo.pinedax

1 Answers

0
votes

I did some test and found you should Call the FocusEntry after PopUp to force the keyboard to come up automatically.

private async void Button_Clicked(object sender, EventArgs e)
{
    var resultQty = await GetInputTextAsync("Test", $"Please goto Bin, the visible stock of the item.", null, Keyboard.Numeric);
}

public async Task<string> GetInputTextAsync(string title, string message, string currentText = null, Keyboard keyboard = null)
{
    if (keyboard == null) keyboard = Keyboard.Default;
    var cts = new TaskCompletionSource<string>();
    var _dialogView = new Plugin.DialogKit.Views.InputView(title, message, currentText, keyboard);
    _dialogView.Picked += (s, o) => { cts.SetResult(o); PopupNavigation.PopAsync(); };
    await PopupNavigation.PushAsync(new PopupPage { Content = _dialogView });

    //Call the FocusEntry after PopUp
    _dialogView.FocusEntry();

    return await cts.Task;
}