Ravindra K Gurung
Ravindra K Gurung

Reputation: 46

How to call LostFocus event of another control from the other control

Calling the LostFocus event of control from other control

Example. : I want to call LostFocus event of Button1 button from the Gotfocus event of Button2 button.

code is :-

private void button2_GotFocus(object sender, RoutedEventArgs e)
        {
          button1.gotFocus // this line giving error.
       }

Upvotes: 1

Views: 5017

Answers (3)

Nitin Joshi
Nitin Joshi

Reputation: 1668

Use following code:

private void button2_GotFocus(object sender, RoutedEventArgs e)
{
    button1.RaiseEvent(new RoutedEventArgs(LostFocusEvent, button1));
}


private void button1_LostFocus(object sender, RoutedEventArgs e)
{

}

If this doesn't solve your problem, post your code and state your problem and purpose clearly so that you can get better solution.

Upvotes: 5

har07
har07

Reputation: 89285

you can just call event handler method of Button1's LostFocus event in button2_GotFocus :

private void button2_GotFocus(object sender, RoutedEventArgs e) 
{ 
    button1_LostFocus(this.button1, null); 
}

Upvotes: 1

Nitin Varpe
Nitin Varpe

Reputation: 10694

Try this

     private void button2_GotFocus(object sender, RoutedEventArgs e)
       { 
         button1_LostFocus(sender,e)

       }

Upvotes: 0

Related Questions