子のいずれかにアタッチされたプロパティを定義するオブジェクト(デコレータ)があります。
これまでのところ、リモートオブジェクトの添付プロパティの設定/取得に問題はありません。
public static readonly DependencyProperty RequiresRoleProperty =
DependencyProperty.RegisterAttached("RequiresRole", typeof (string), typeof (UIElement),
new FrameworkPropertyMetadata(
null,
FrameworkPropertyMetadataOptions.AffectsRender,
OnSetRequiresRole));
[AttachedPropertyBrowsableForChildrenAttribute(IncludeDescendants=true)]
public static string GetRequiresRole(UIElement element)
{
return element.GetValue(RequiresRoleProperty) as string;
}
public static void SetRequiresRole(UIElement element, string val)
{
element.SetValue(RequiresRoleProperty, val);
}
ただし、このアタッチされたプロパティにOnSetCallbackを設定しているので、設定ロジックは、この要素が子であるデコレータ(MyClass)への参照が必要です。
コールバックのタイプシグニチャー:
void Callback(DependencyObject d, DependencyPropertyChagnedEventArgs args)
d
アタッチされたプロパティが設定されているオブジェクトです。args.NewValue
&args.OldValue
はプロパティの実際の値です。
アタッチされたプロパティが属する包含要素への参照を収集する最良の方法は何ですか?