set cursor after button content click in password box wpf

Kran2022 386 Reputation points

Hi All:
I have a password control box and there is small grid keybaord to enter password, issue is that the moment when i click on the button to enter the password, the cursor deosn't move after password box content
How can i set the cursor in the password box after the content got enterted by button click? in my case the cursor is set before the content.


  private void bkletter_Click(object sender, RoutedEventArgs e)  
             ppassword.Password = ppassword.Password + "K";  
             FocusManager.SetFocusedElement(this, ppassword);  
        <PasswordBox Name="ppassword" HorizontalAlignment="Left" Margin="111,50,0,0" FocusManager.IsFocusScope="True"  
                     VerticalAlignment="Top" Height="33" Width="249" PasswordChar="*" FontSize="25" KeyDown="ppassword_KeyDown"   />  
<Button Content="K" Name="bkletter" Grid.Row="0" Grid.Column="0"   
                        VerticalAlignment="Top" Width="81" Height="44" IsCancel="True" FontSize="28" Background="White" Click="bkletter_Click" >  
Microsoft Technologies based on the .NET software framework.
3,643 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,640 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.7K Reputation points

    Some articles suggests this code:

    var a = new KeyEventArgs( Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.End )  
        RoutedEvent = Keyboard.KeyDownEvent  
    InputManager.Current.ProcessInput( a );  

    Add it after FocusManager.SetFocusedElement.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful