2010-08-23 2 views
0

다음은 클래스 MyContainer의 계층 구조입니다. Panel에는 ChildrenMyContainer이 있습니다. PanelChildren도 사용할 수 있습니까?Silverlight ContentProperty on abstract 클래스 패널

[ContentProperty("Children", true)]의 의미는 무엇입니까? 요약 설명 :

클래스가 XAML 프로세서에 의해 구문 분석 할 때 내용 재산으로 해석 할 수있는 클래스 의 재산

를 지정합니다.

그러나 나는 그가 무슨 뜻인지 이해하지 못하고 있습니까?

[ContentProperty("Children", true)] 
public abstract class Panel : FrameworkElement 
{ 
    // 
    // Summary: 
    //  Gets the collection of child elements of the panel. 
    // 
    // Returns: 
    //  The collection of child objects. The default is an empty collection. 
    public UIElementCollection Children { get; } 
} 

public class Canvas : Panel 
{....} 

public class MyContainer : Canvas 
{ 

    public MyContainer(); 

    public ObservableCollection<MyObject> Children {get;} 
} 

답변

1

ContentProperty 속성은 다음 두 요소가 동일 함을 의미합니다. Canvas의 Children 속성은 Canvas의 기본 콘텐츠입니다.

<Canvas> 
    <TextBlock Text="Hello"/> 
    <Button Content="World"/> 
</Canvas> 

<Canvas> 
    <Canvas.Children> 
     <TextBlock Text="Hello"/> 
     <Button Content="World"/> 
    </Canvas.Children> 
</Canvas>