私は依存関係のプロパティについて少し研究を行い、混乱を招きました。 ランタイムは、DependencyPropertyがどのオブジェクトに属しているかをどのように判断しますか?C#DependencyProperty - プロパティをオブジェクトにマップする方法
すべてが同じDependencyPropertyを登録する(同じタイプの)オブジェクトのコレクションを想像してください。プロパティはTextBoxにバインドされ、TexBoxesは上下に表示されます。
まず、それぞれのTextBoxが異なるDependencyPropertyにバインドされていますか?私はそう思うが、100%確実ではない。 Second:もしそうなら、ランタイムはDependencyPropertyがマップされるべきオブジェクトをどのように決定するのですか? DependencyPropertyを登録するときは、MyClockControlの例でオブジェクトタイプを指定するだけです。コールされたインスタンスを呼び出されたメソッドから取得する方法はないので、オブジェクトを解決する方法を取得しないでください。依存プロパティにアクセスするときに、プロパティを「含む」と複数のプロパティの正しいものが返されます。すべての答えをhttp://www.wpftutorial.net/dependencyproperties.html
// Dependency Property
public static readonly DependencyProperty CurrentTimeProperty =
DependencyProperty.Register("CurrentTime", typeof(DateTime),
typeof(MyClockControl), new FrameworkPropertyMetadata(DateTime.Now));
// .NET Property wrapper
public DateTime CurrentTime
{
get { return (DateTime)GetValue(CurrentTimeProperty); }
set { SetValue(CurrentTimeProperty, value); }
}
おかげから
例。 (DependencyObject
の)