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