3

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?

Arpit Khandelwal
  • 1,743
  • 3
  • 23
  • 34
  • Just sharing in case someone else has a similar problem that I had. I had a custom control that I could get focus onto the control, but not the textbox in the control that I really wanted focus to go into. The solutions above didn't work with this variation of the problem. Came across this link which solved the problem. https://www.codeproject.com/tips/478376/setting-focus-to-a-control-inside-a-usercontrol-in – Jeff Oct 28 '21 at 19:28

2 Answers2

3

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.

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
1

You can set Focusable property to false by a Setter in your custom control's template. Both on the control and on the various elements inside.

Mikhail Orlov
  • 2,789
  • 2
  • 28
  • 38