How to find out if UserControl is active other than using IsFocused

I am working on a WPF project and I am trying to fire an event every time some userControls become active or inactive.

These userControls have many other controls inside them.

I tried to achieve this using userControl GotFocusand events LostFocus, but these events do not work as I need, because userControl loses focus when I work with controls inside it.

So my question is: Is there a way to use userControl as Activewhile the user is working with the controls inside it, and when the user moves to another userControl, does this first get Inactive???

Thanks in advance.

+5
source share
2 answers

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.

+2
source

, workarounnd , , , , , , , , . ,

0

All Articles