Say I have the following Code:
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!
}
Is there a way in the OnLabelChanged event to get the object it is attached to?
For example, say I use this like this:
<TextBox Controls:HotKeyHelper.Label="{Binding ElementName=SomeLabel}"/>
Is there a way to get a reference to the SomeLabel label in my OnLabelChanged event?
e.NewValue?obj should be the object the attached property is set on, i doubt that you’ll want to cast it to Label as it can be anything…