I could solve my problem thanks to the comments of @LPL and @Rachel.
I had to use an event UIElement.IsKeyboardFocusWithinChangedand it worked great.
At first, I had a problem in that the callback method went up indefinitely, but the actual problem was in what I showed MessageBoxon every event IsKeyboardFocusWithinChanged, so this caused that IsKeyboardFocusWithin, and it created an infinite loop. But thanks to Rachel’s advice, I could figure out how to solve it.
Dante source
share