说我有以下代码:
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标签的引用?