Reputation: 2715
I'm going to focus hell right now in my WPF application. Focus is jumping around between elements, and seemingly disappearing only to come up on another element when the tab key is repeatedly pressed.
Is there a property I can bind a label on to or something that will simply just tell me what the heck the keyboard focus is latched on to at the time? Sometimes I can see the ant trail (dotted line) indicating something has focus, but I can't tell what it is surrounding to turn the keyboard focus off!
Upvotes: 6
Views: 2094
Reputation: 10039
I can highly recommend reading this article. It comes with some source code that can help debug focus issues, I often end up using this code to help with my own focus issues.
http://julmar.com/blog/programming/part-1-its-basically-focus/
Upvotes: 0
Reputation: 3285
Maybe you could try setting proper values to the TabIndex property of the controls? This should make the focus "jump" over the "path" you want it to jump when pressing Tab.
Upvotes: 0
Reputation: 82517
What you are likely looking for is:
(System.Windows.Input.Keyboard.FocusedElement as FrameworkElement).Name
You will have to setup a DependencyProperty for it so that you can bind to it though.
Vaccano
Upvotes: 2
Reputation: 24319
Focus problems can be very hard to analyze, since almost everything you do with a debugger affects focus.
A better question to ask is why is focus jumping around? Are you explicitly setting focus? Maybe a little hint about your implementation (i.e. which container(s) you are using) might help us answer.
Upvotes: 0