![](/img/trans.png)
[英]How to subscribe to event of Attached property inside custom control in Silverlight?
[英]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标签的引用?
obj应该是附加属性设置的对象,我怀疑您会将其强制转换为Label,因为它可以是任何东西...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.