locked
Textbox gets focus when scrolling RRS feed

  • Question

  • Hi everyone.

    I have a TextBox that launches popup when it's get focus.

    This TextBox is inside a ScrollViewer.

    When I want to scroll the page and I press on this TextBox to start scrolling, the popup shows up.

    The problem is that I don't want it to show up when I just want to scroll.

    I tried to use the 'Tapped' event instead of 'GotFocus' and that's works great, but when user focuses the TextBox using the 'Tab' key the event, of course, not fires - and that's a problem...

    Is there a workaround?

    Tuesday, August 28, 2012 1:13 PM

Answers

  • Here's a suggested workaround for this issue.  You can use the approach you're already using, with the Tapped event, but also handle the TextBox's Focus event.  The trick is to only take action (i.e. call the same handler as Tapped is getting) if you see focus come from the Keyboard.  Like so:

            private void TextBox_GotFocus_1(object sender, RoutedEventArgs e)
            {
                if (((TextBox)sender).FocusState == Windows.UI.Xaml.FocusState.Keyboard)
                {
                    // call the Tapped event handler... 
                }
            }

    Also, note that if you set the AcceptsReturn property of your textbox to "True", you can see that the TextBox already has its own ScrollViewer... so you may not need to have two nested scrollviewers in your scenario.

    Hope this helps,
    Matt


    XAML SDET Lead : Input / DirectManipulation / Accessibility

    Wednesday, August 29, 2012 4:49 PM

All replies

  • I can't imagine that there's a workaround for behavior that you've explicitly told it to do.  You either want it to pop up on focus or you don't, you have to decide which it is.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, August 28, 2012 7:24 PM
    Moderator
  • Hi Slsa,

    This is a little confusing but I think I understand.

    What you want is:

    Focus on a TextBox should pop up something except, if the focus is in conjunction with a swipe which you are using to scroll.

    Is that it?

    -Jeff


    Jeff Sanders (MSFT)


    Tuesday, August 28, 2012 7:49 PM
    Moderator
  • If by scroll you mean pan (scrolling with touch gestures), then you'll be working around a bug. Controls shouldn't take focus on a pan, but there's a bug that makes this happen.

    Wednesday, August 29, 2012 5:38 AM
  • Hi Chipalo. Yes, I mean panning.

    Hi Jpsanders. Yes, you understood me correctly.

    So... There is no solution...?

    • Edited by SLSA Wednesday, August 29, 2012 9:05 AM
    Wednesday, August 29, 2012 9:05 AM
  • Here's a suggested workaround for this issue.  You can use the approach you're already using, with the Tapped event, but also handle the TextBox's Focus event.  The trick is to only take action (i.e. call the same handler as Tapped is getting) if you see focus come from the Keyboard.  Like so:

            private void TextBox_GotFocus_1(object sender, RoutedEventArgs e)
            {
                if (((TextBox)sender).FocusState == Windows.UI.Xaml.FocusState.Keyboard)
                {
                    // call the Tapped event handler... 
                }
            }

    Also, note that if you set the AcceptsReturn property of your textbox to "True", you can see that the TextBox already has its own ScrollViewer... so you may not need to have two nested scrollviewers in your scenario.

    Hope this helps,
    Matt


    XAML SDET Lead : Input / DirectManipulation / Accessibility

    Wednesday, August 29, 2012 4:49 PM
  • Thank you.

    This is works.

    Tuesday, September 4, 2012 11:46 AM