locked
[UWP]textbox does not get focus in UWP app for mobile RRS feed

  • Question

  • TextBox does not get focus in UWP app for mobile. It works fine on desktop and it also work fine in Windows Mobile app 8.1 but it does  not work on UWP app for mobile.

    I've this line of c# code yet it wont focus on the textbox

             private void SKULookup_Loaded(object sender, RoutedEventArgs e)
            {
                    txtBarcode.Focus(FocusState.Keyboard);
            }

    Is there any solution for this?

    Kind help is appreciated.

    Thanks and Regards


    Thursday, March 2, 2017 6:28 PM

Answers

  • Finally the issue has been resolve. Page.BottomAppBar should be IsOpen= "False" then everything works fine.

    Thanks

    Thursday, March 2, 2017 11:15 PM

All replies

  • I assume SKULookup is the page the texbox is located? Your code should work just fine. Could you please show the XAML declaration of your TextBox? Here a little demo app that works for me https://1drv.ms/u/s!AvYKZWh6mpbZgYK_dejTUCxVF0c1AvE

    Please remember to mark the replies as answers if they answered your question!


    Thursday, March 2, 2017 8:55 PM
  • Thanks for the quick reply.

    TextBox focus is not working in any of the mobile app pages but it works fine on desktop app pages of the same application. Yes, SKULookup is the page. However, here is the textbox xaml code:

    <TextBox x:Name="txtBarcode" TabIndex="0" HorizontalAlignment="Left" Height="41" Margin="12,14,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="256" KeyDown="txtBarcode_KeyDown_1"/>

    Thank you.

    Thursday, March 2, 2017 9:08 PM
  • Did you try my demo App. Does that work for you? Do you test on WP8.1 or W10M, device or emulator?

    Please remember to mark the replies as answers if they answered your question!

    Thursday, March 2, 2017 9:12 PM
  • Sorry, just saw that your problem is specific to W10M. However, I can still not reproduce your problem. Since you setting the focus in code behind you might wanna try

    txtBarcode.Focus(FocusState.Programmatic);


    Please remember to mark the replies as answers if they answered your question!

    Thursday, March 2, 2017 9:29 PM
  • I saw the demo which is for Windows Mobile 8.1. We've Windows Mobile App 8.1 and thats working fine in all areas including texbox focus already. We're trying to migrate Windows Mobile app 8.1 to Windows Universal App and mobile part of it does not work for textbox focus. Where as desktop part works fine. On Honeywell integrated windows 10 device.

    Thanks




    Thursday, March 2, 2017 9:29 PM
  • Do you mind sending me a small repro project where you experience the problem?

    Please remember to mark the replies as answers if they answered your question!

    Thursday, March 2, 2017 9:32 PM
  • I tried both Programmatic and Keyboard but none works.
    Thursday, March 2, 2017 9:49 PM
  • Do you test or device or emulator?

    Please remember to mark the replies as answers if they answered your question!

    Thursday, March 2, 2017 9:50 PM
  • Please try this demo project. https://1drv.ms/u/s!AvYKZWh6mpbZgYK_ebnymS2Gfjo903Q It works perfectly fine for me.

    Please remember to mark the replies as answers if they answered your question!

    Thursday, March 2, 2017 10:09 PM
  • I found the issue. Page.BottomAppBar is taking away the focus on page load and ignoring textbox focus. So, when I remove the page.bottomappbar then it works. But I need the ButtomAppBar too. What do I do here?

    Thanks

    Thursday, March 2, 2017 11:03 PM
  • Finally the issue has been resolve. Page.BottomAppBar should be IsOpen= "False" then everything works fine.

    Thanks

    Thursday, March 2, 2017 11:15 PM