I have hosted my custom winform control to the WPF project. I have handled the KeyDown event of my custom control to navigate to the next control when the Tab or Shift+Tab key is pressed.
Here is my code for handling the Tab key,
protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
if (e.Handled)
return;
if (this.AllowStandardTab)
{
Form form = this.FindForm();
if (form != null)
{
if (e.KeyData == (Keys.Tab | Keys.Shift))
{
form.SelectNextControl(this, false, true, false, true);
return;
}
else if (e.KeyData == Keys.Tab)
{
form.SelectNextControl(this, true, true, false, true);
return;
}
}
}
}
Its working properly in winforms and navigate to the next control. But its not working in the hosted wpf project.
How can I detect wheter the control is hosted in wpf and moves the focus to the next wpf window while pressing the Tab key?