繁体   English   中英

在OnChange事件中找到附加属性附加到的控件

[英]Find the control that an Attached Property is attached to in the OnChange Event

说我有以下代码:

   public static DependencyProperty LabelProperty =
        DependencyProperty.RegisterAttached(
            "Label",
            typeof(Label),
            typeof(HotKeyHelper),
            new FrameworkPropertyMetadata(default(Label), OnLabelChanged)
        );

    public static void SetLabel(DependencyObject obj, Label value)
    {
        obj.SetValue(LabelProperty, value);
    }

    public static Label GetLabel(DependencyObject obj)
    {
        return (Label)obj.GetValue(LabelProperty);
    }

    private static void OnLabelChanged(DependencyObject obj,
         DependencyPropertyChangedEventArgs e)
    {
        Label label = obj as Label;

        // Question is for Right Here!
    }

OnLabelChanged事件中是否有一种方法可以获取附加到该对象的对象?

例如,说我这样使用:

  <TextBox Controls:HotKeyHelper.Label="{Binding ElementName=SomeLabel}"/>

有没有办法在OnLabelChanged事件中获得对SomeLabel标签的引用?

e.NewValue

obj应该是附加属性设置的对象,我怀疑您会将其强制转换为Label,因为它可以是任何东西...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM