Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Focus with AutoFocusBehavior #60

Open
SuperJMN opened this issue Apr 21, 2017 · 4 comments
Open

Unexpected Focus with AutoFocusBehavior #60

SuperJMN opened this issue Apr 21, 2017 · 4 comments

Comments

@SuperJMN
Copy link

SuperJMN commented Apr 21, 2017

Given this XAML, I expect that upon pressing Enter in the PasswordBox, the Focus should be set to the Button. However, the TextBox is focused instead.

<Page
    x:Class="App1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App1"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    xmlns:behaviors="using:Cimbalino.Toolkit.Behaviors"
    mc:Ignorable="d">
    <interactivity:Interaction.Behaviors>
        <behaviors:AutoFocusBehavior />
    </interactivity:Interaction.Behaviors>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <StackPanel >
            <TextBox />
            <PasswordBox />
        </StackPanel>
        <Button Grid.Row="1">CONTINUE</Button>
    </Grid>
</Page>

IMHO, it would be more useful if the button was focused, since the user can save time this way and will intuitively press Enter again to "Continue"

@pedrolamas
Copy link
Member

The AutoFocusBehavior follows the control's Control.TabIndex which if not specified, it will default to the order of the controls as they appear in the XAML (in this case TextBox -> PasswordBox -> Button).

You can always specify the TabIndex on each of the controls to get the order you want!

If all you want is to invoke a command when the Enter key is pressed on the TextBox control, you can attach a EnterKeyBehavior to it!

@SuperJMN
Copy link
Author

Thanks for the lightning fast answer!

I would expect that pressing the Tab Key and the Enter Key would have the same behavior, while it's not true.

In the XAML I posted, if you press Tab, this is the order you'll get

  • TextBox => PasswordBox => Button

However, pressing Enter will lead you to:

  • TextBox => PasswordBox

I expected both to be the same

@pedrolamas
Copy link
Member

That's a fair point... when I wrote the behavior, I targeted only TextBox and PasswordBox, so an update will be required to get the other in!

For now, my advice is for you to copy the behavior code directly to your project and make the appropriate changes (removing the last bit on this line should suffice)

@SuperJMN
Copy link
Author

I'll do that. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants