Reputation: 46
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
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
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
Reputation: 10694
Try this
private void button2_GotFocus(object sender, RoutedEventArgs e)
{
button1_LostFocus(sender,e)
}
Upvotes: 0