I am trying to give a specific control keyboard focus during a sequence of presentation changes. Say a control was in a visibility state of hidden. In a function call I can change its visibility to visible, set the keyboard focus on it with no problems. However if the control was set to a visibility of collapsed and I try to set the visibility back to visible then set focus on it, it does not take.
Is there a process I can use to allow the control to move from a collapsed state, to a visible state and take keyboard focus?
It's probably a timing issue where the control you set to visible is not ready to accept focus yet. This can happen fairly frequently when dealing with dynamic UI changes.
You should still be able to focus your control but you'll need to queue the focus action until after the control has been properly initialized. Simply using a BeginInvoke call like shown below, should do the trick.
Dispatcher.BeginInvoke(() =>
{
//Set focus here
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With