Google の多くの記事で、オブジェクトの各インスタンスの値を維持する KeyValue メカニズムがあるため、DependencyProperty は静的であると述べられています。
しかし問題は、DependencyProperty に対して GetValue / SetValue を呼び出すと、各インスタンスを識別してキーを生成し、オブジェクトのさまざまなインスタンスの HashTable から値を読み取り/保存する方法です。
例: TestDp の 2 つのインスタンスを作成し、両方のインスタンスの TestDProperty の値を設定する場合、SetValue はどのように各インスタンスを識別し、それに応じて DependencyProperty 値をハッシュ テーブルに保存しますか?
DependencyObject の GetValue と SetValue のコードを確認しましたが、各インスタンスをどのように区別するかまだわかりません。コード this.LookupEntry(dp.GlobalIndex) は EntryIndex を取得しますが、オブジェクトの各インスタンスを区別するために GlobalIndex がどのように生成されるかはわかりません。
public class TestDp : DependencyObject
{
protected static DependencyProperty dpTest = DependencyProperty.Register("TestDProperty", typeof(string), typeof(TestDp));
public string TestDProperty
{
get
{
var r = (string)GetValue(dpTest);
return r;
}
set
{
SetValue(dpTest, value);
}
}
}