Search code examples
wpffocuscontrols

WPF: Controlling focus in a custom control


I am developing a custom control (say BoxControl) which will have many controls in it like a textbox, few buttons etc.

I will have many BoxControls in a row and while navigating via tabs, I want it to behave like when a BoxControl gets focus, it always passes the focus to its textbox and when its textbox loses the focus, the entire BoxControl loses the focu and passes the focus to next BoxControl.

Any ideas how can it be done?


Solution

  • You will need to add an event handler to your BoxControl to handle the GotFocus event and then put the focus on its text box.

    You will need also to add an event handler to the LostFocus event of the textbox and then you can raise a custom event on BoxControl so it's controller can know that has to pass the focus to the next BoxControl

    Hope it helps.