나는 무엇이 일어날지를보기 위해 이것을 시험해 보았지만 효과가 있었지만 왜 그런지는 모른다. 누군가가 DependencyProperties
의 배경에서 무슨 일이 일어 났는지 설명 할 수 있습니까?DependencyProperty 이상한 행동
은 내가 DependencyProperty
을 선언하지만 다른 클래스에서 내가 GetValue
및 SetValue
를 사용하여 DependencyProperty
것을 목표로하는 클래스가 있습니다.
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를 등록하지 않았지만 사용할 수 있습니다. 후드 아래에서 무슨 일이 일어나는지 누군가가 말해 줄 수 있습니까?
중복 가능 : http://stackoverflow.com/questions/6843877/difference-between-attached-and-non-attached-dependency-properties-in-silverligh – Blachshma