從屬性更改回調中獲取附屬屬性的實例是否有附屬屬性類型?從依賴項屬性更改回調中獲取附加屬性實例
換句話說,如果您有:
public class MyAttachedPropertyClass
{
public static readonly DependencyProperty MyProperty = DependencyProperty.RegisterAttached(
"My", typeof(int), typeof(MyAttachedPropertyClass), new FrameworkPropertyMetadata(0, OnMyPropertyChanged));
private static void OnMyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
//TODO: access instance of MyAttachedPropertyClass
}
}
我需要訪問MyAttachedPropertyClass的實例,這樣我可以設置另一個屬性坐在類型的值。
不知道我明白你想做什麼。你能再詳細一點嗎? – 2010-12-16 14:16:08
我在MyAttachedPropertyClass上有一個基於實例的字段,我需要將OnMyPropertyChanged中該字段的值設置爲e.NewValue的整數值。由於OnMyPropertyChanged是靜態的,我無法在靜態上下文中訪問此實例字段。 – devdigital 2010-12-16 14:19:47
我不確定我是否理解了你的問題,或者你想要做什麼,但是如果你只需要屬性發生變化的對象實例(我最好猜測你到底是什麼意思),那就是你的' DependencyObject d'參數。 – 2010-12-16 22:43:22