【问题标题】:WPF label counterpart for HTML "for" attributeHTML“for”属性的 WPF 标签对应项
【发布时间】:2010-10-15 11:33:24
【问题描述】:

WPF 中是否有一些属性可以添加到元素中,所以当我单击它时,目标控件会获得焦点?我找到的最接近的东西是“目标”,但它只适用于访问键并且单击它没有效果。

【问题讨论】:

  • 有点相关。标签具有Target 属性,该属性指向当用户按下标签的访问键时获得焦点的元素。

标签: wpf label target for-attribute


【解决方案1】:

覆盖标签控件

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

    protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
    {
        if (Target != null) Target.Focus();
        base.OnMouseDown(e);
    }
}

【讨论】:

    【解决方案2】:

    不,但可以使用 attached behavior 来解决此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-09
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-28
      • 1970-01-01
      • 2013-01-17
      相关资源
      最近更新 更多