0
說我有以下代碼控制:查找附加屬性附加到在onchange事件
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',因爲它可以是任何東西... –