プロパティが変更されるたびにコードを実行したい。以下はある程度機能します。
public partial class CustomControl : UserControl
{
public bool myInstanceVariable = true;
public static readonly DependencyProperty UserSatisfiedProperty =
DependencyProperty.Register("UserSatisfied", typeof(bool?),
typeof(WeeklyReportPlant), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnUserSatisfiedChanged)));
private static void OnUserSatisfiedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Console.Write("Works!");
}
}
これは、UserSatisfiedProperty の値が変更されたときに "Works" を出力します。問題は、OnUserSatisfiedChanged を呼び出している CustomControl のインスタンスにアクセスして、myInstanceVariable の値を取得する必要があることです。これどうやってするの?