3
votes

This one is a bit tricky to explain.

I have a usercontrol with some textboxes. I also have a menu just above this usercontrol in the same window. Whenever I tab away, the LostFocus fires correctly on the textbox, and this is what I want. Strangely enough, if I click the Menu button on top of my window, the LostFocus event does not fire on the textbox. Is there an elegant way to make sure that my menu properly allows LostFocus to fire on any controls which last had focus?

I also want to avoid having to Update BindingExpressions otherwise I would likely be doing this for N textboxes, which is undesirable.

I can't imagine it is too difficult to achieve this.. I just don't understand how this doesn't work: in most other situations LostFocus always fires.

Any ideas? Thank you.

1
The Menu does not take the focus. By design. Why do you want it to?Henk Holterman
Take focus, so the previous control can behave accordingly..Mani5556
If there was a way for doing something OnClick of a menu command, like determining what has focus, and then dealing with it.. that is a different challenge...Mani5556
If the TextBox has focus and you click on another element such as a menu that does not really capture the mouse, the TextBox will still retain focus, hence LostFocus does not fire. You may need to delay re-evaluating your expressions until when it is really needed.Klaus Nji

1 Answers

0
votes

Is the menu WPF as well or Winforms / UnManaged? If either of the two then the lost focus event does not fire. This can play havoc with WPF controls as many time a save or other data function is being performed from the menu. To counter this I have had to implement multiple ways to combat this. The easiest way was to implement a mouse leave event on the user control itself and perform any actions you require manually in code.