Hi I can not focus on the parent control. I have a control that fits on a canvas. If I click on this control, I need to set the focus to the canvas in order to handle some keyboard events. However, despite the fact that I tried to adjust the focus in this way
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{
base.OnPreviewMouseDown(e);
Canvas designer = VisualTreeHelper.GetParent(this) as Canvas;
designer.Focus() ;
Keyboard.Focus(designer);
}
Keyboard events attached to the canvas do not fire.
source
share