I'm trying to debug some issues with missing/extra tab stops. Is there some kind of global event that I can attach to so that I can log which element got focus whenever focus changes? Thanks! Here's what I'm doing right now, which works well enough, but I'm still curious as to whether there's another way:
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(0.2);
timer.Tick += onTick;
timer.Start();
// ...
private object LastFocusedElement;
private void onTick(object sender, EventArgs e)
{
object elem = FocusManager.GetFocusedElement();
if(LastFocusedElement != elem)
{
LastFocusedElement = elem;
System.Diagnostics.Debug.WriteLine("+++FOCUS+++ Focus changed to: " + elem + (elem == null ? "" : " (" + elem.GetType().Name + ")"));
}
}