Click here to Skip to main content
16,007,779 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have two text boxes and two buttons...I had written some logic in first text box Lost Focus event.As soon as i click the keyboard tab cursor will blink at second text box..Now i want to select the button 1 or button 2 instead of second text box.How can i achieve this...any idea...suggestion.

I added at the end of first text box LostFocus event

C#
Keyboard.Focus(btnName);

FocusManager.SetFocusedElement(this, btnName);


these two didn't work

Thanks in advance
Posted

set
<Button Name="btn" KeyboardNavigation.TabIndex="0"/>


next u can set which control need to navigate as soon as your press keyboard tab key

<Button Name="btn1" KeyboardNavigation.TabIndex="1"/>


by setting in xaml i solved my problem
 
Share this answer
 
v2
Hi my friend. i create a small example that contains your controls.
you are right. i think this behavior is because of Control.Property precedeny.
and you must write into xaml:

XML
<Grid>
        <TextBox Height="23" Width="80" HorizontalAlignment="Left" LostFocus="TextBox_LostFocus"/>
        <TextBox Height="23" Width="80" HorizontalAlignment="Left" Margin="100 80 0 0" KeyboardNavigation.IsTabStop="False"/>
        <Button x:Name="myButton" Content="first" Height="23" Width="80" VerticalAlignment="Top"/>
        <Button Content="second" Height="23" Width="80" VerticalAlignment="Center"/>
    </Grid>



and your code begind:
C#
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
      {
          //your logic
          myButton.Focus();
      }
 
Share this answer
 
v3
Comments
keerth516 24-Jul-13 9:59am    
thanks for the reply ali but i solved that issue by myself...your answer is also correct way of doing it in .cs
check this one..


C#
System.Threading.ThreadPool.QueueUserWorkItem(
                  (a) =>
                  {
                      btnName.Dispatcher.Invoke(
                      new Action(() =>
                      {
                          btnName.Focus();

                      }));
                  }
                  );




source:

http://stackoverflow.com/questions/673536/cant-set-focus-to-a-child-of-usercontrol
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900