2010-08-23 25 views
0

以下是我的類MyContainer的層次結構。請注意0​​有一個Children以及MyContainer。我還可以使用PanelChildren嗎?關於抽象類面板上的Silverlight ContentProperty

[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>