Sonhja
Sonhja

Reputation: 8448

Is it possible to detect which element is focused when focus changes?

I'm developing an application in WPF in which I'm trying to control tab order. For that purpose, I'm deleting tab control of these elemnents that don't need to have a tab stop with this:

KeyboardNavigation.IsTabStop="False"

But I'm loosing a tab somewhere, and I was wondering if there is a way to check which exact element gained focus at each focus change.

I searched this, but I'm not sure how to apply it.

Any idea on how to detect each focused element?

Upvotes: 1

Views: 1057

Answers (2)

AdamMarty2000
AdamMarty2000

Reputation: 11

I know it's been a while, but I think people who will search for an answer to this question should know that now Visual Studio provides users with a tool called "Track Focused Element" in "Live Visual Tree".

Enable Live Visual Tree

Select Track Focused Element

It highlights the currently focused element in your app. This tool really helped me in debugging app and fixed a really annoying bug.

Upvotes: 0

Lukazoid
Lukazoid

Reputation: 19416

As this is only required at design time, it seems a programmatic solution is not required so one option is to use Snoop.

By attaching Snoop to your WPF application, you will be able to to see which element currently has focus. The focused element also appears as a clickable link, which you may click to see the exact location within the visual tree.

Snoop Screenshot

If you look at the bottom of this Snoop you can see the currently focused element is a ComboBox called "AvailableDevicesComboBox".

Upvotes: 2

Related Questions