2013-02-06 4 views
0

나는 무엇이 일어날지를보기 위해 이것을 시험해 보았지만 효과가 있었지만 왜 그런지는 모른다. 누군가가 DependencyProperties의 배경에서 무슨 일이 일어 났는지 설명 할 수 있습니까?DependencyProperty 이상한 행동

은 내가 DependencyProperty을 선언하지만 다른 클래스에서 내가 GetValueSetValue를 사용하여 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를 등록하지 않았지만 사용할 수 있습니다. 후드 아래에서 무슨 일이 일어나는지 누군가가 말해 줄 수 있습니까?

+0

중복 가능 : http://stackoverflow.com/questions/6843877/difference-between-attached-and-non-attached-dependency-properties-in-silverligh – Blachshma

답변

0

나는 당신에게 보여주고 싶은 이미지를 봤습니다. 아래 링크를 참조하십시오. DP의 개념은 잘 설명되어 있습니다.

http://www.abhisheksur.com/2011/07/internals-of-dependency-property-in-wpf.html

그리고 당신은 초대 앱에서 MyControl을 사용할 때,의 직접 하단 라인에 가자, DP가 자동으로 등록되어 포함되어 있습니다. 이것이 DP가 정적 접두사를 사용하는 이유입니다. DP 신고서에 static readonly이 게시 된 이유는 https://stackoverflow.com/a/5610015/361100 링크 (Priyank의 인용 답변)입니다.

+0

.Register (...를 사용하면 어떻게됩니까? rameworkPropertyMetadataOptions.Inherits)? AttachedProperty가 아니지만 상속을 시도합니다. – cyberist