4

Is there some attribute in WPF that I can add to element, so when I click it the target control get focus? The closest thing I have found is 'Target', but it works only with access keys and clicking it has no effect.

alex2k8
  • 42,496
  • 57
  • 170
  • 221
  • Somewhat related. Labels have the [Target](https://learn.microsoft.com/en-us/dotnet/api/system.windows.controls.label.target?view=netframework-4.8) property, that points to the element which receives focus when the user presses the label's access key. – Nick Alexeev May 03 '19 at 22:57

2 Answers2

2

override the Label control

public class LabelEx : Label
{
    public LabelEx() : base() {}

    protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
    {
        if (Target != null) Target.Focus();
        base.OnMouseDown(e);
    }
}
Gnought
  • 485
  • 5
  • 12
1

No, but an attached behavior could be made to work for this.

wekempf
  • 2,738
  • 15
  • 16