locked
how to change the default focus from a textbox to a button in windows store app

    Question

  • how to change the default focus from a textbox to a button in windows store app
    Monday, November 19, 2012 11:53 AM

Answers

  • Please try these codes:

    aml:

            <StackPanel>
                <TextBox x:Name="textBox"></TextBox>
                <Button x:Name="button1" Click="button1_Click_1">Set focus</Button>
            </StackPanel>

    Code:

            private void button1_Click_1(object sender, RoutedEventArgs e)
            {
                button1.Focus(Windows.UI.Xaml.FocusState.Programmatic);
            }

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Jesse Jiang Tuesday, November 20, 2012 6:07 AM
    • Marked as answer by Jesse Jiang Monday, November 26, 2012 6:30 AM
    Tuesday, November 20, 2012 6:06 AM
  • I think

    <Grid ... Loaded="OnGridChildLoaded">
    </Grid>

    Process Loaded method and set Button getting your default focus.

    Button_Test->Focus(Windows::UI::Xaml::FocusState::Keyboard);
    

    • Marked as answer by Jesse Jiang Monday, November 26, 2012 6:30 AM
    Wednesday, November 21, 2012 5:22 AM

All replies

  • Please try these codes:

    aml:

            <StackPanel>
                <TextBox x:Name="textBox"></TextBox>
                <Button x:Name="button1" Click="button1_Click_1">Set focus</Button>
            </StackPanel>

    Code:

            private void button1_Click_1(object sender, RoutedEventArgs e)
            {
                button1.Focus(Windows.UI.Xaml.FocusState.Programmatic);
            }

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Jesse Jiang Tuesday, November 20, 2012 6:07 AM
    • Marked as answer by Jesse Jiang Monday, November 26, 2012 6:30 AM
    Tuesday, November 20, 2012 6:06 AM
  • I think

    <Grid ... Loaded="OnGridChildLoaded">
    </Grid>

    Process Loaded method and set Button getting your default focus.

    Button_Test->Focus(Windows::UI::Xaml::FocusState::Keyboard);
    

    • Marked as answer by Jesse Jiang Monday, November 26, 2012 6:30 AM
    Wednesday, November 21, 2012 5:22 AM