WPF label counterpart for HTML “for” attribute

后端 未结 2 1359
孤独总比滥情好
孤独总比滥情好 2021-01-13 18:51

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 w

2条回答
  •  春和景丽
    2021-01-13 18:56

    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);
        }
    }
    

提交回复
热议问题