WPF label counterpart for HTML “for” attribute

2019-02-18 18:14发布

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.

2条回答
等我变得足够好
2楼-- · 2019-02-18 18:33

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);
    }
}
查看更多
聊天终结者
3楼-- · 2019-02-18 18:42

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

查看更多
登录 后发表回答