何が起こるかを確認するためだけにこれを試してみましたが、うまくいきましたが、その理由はわかりません. の背景で何が起こっているのか誰か説明してもらえますかDependencyProperties
?
a を宣言するクラスがありますが、別のクラスでは、 andを使用してDependencyProperty
それをターゲットにしています。DependencyProperty
GetValue
SetValue
次に例を示します。
public class DependencyProperties : DependencyObject
{
public Size EstimatedSize
{
get { return (Size)GetValue(EstimatedSizeProperty); }
set { SetValue(EstimatedSizeProperty, value); }
}
public static readonly DependencyProperty EstimatedSizeProperty =
DependencyProperty.Register("EstimatedSize", typeof(Size), typeof(DependencyProperties), null);
}
public class MyControl: ContentControl
{
public Size CalculatedSize
{
get { return (Size)GetValue(DependencyProperties.EstimatedSizeProperty); }
set { SetValue(DependencyProperties.EstimatedSizeProperty, value); }
}
protected override OnApplyTemplate()
{
// This works but why? How is it possible to do this? What is happening under the hood?
this.CalculatedSize = new Size(123, 123);
}
}
なぜこれができるのでしょうか?この例の背景で何が起こっているのでしょうか? MyControl クラスは DP を登録しませんでしたが、DP を使用できます。ボンネットの下で何が起こっているのか誰か教えてもらえますか?