简体   繁体   中英

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.
       }

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.

Try this

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

       }

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); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM