开发者

Silverlight ContentProperty on abstract class Panel

Here is a hierarchy of my class MyContainer. Notice that the Panel has a Children as well as MyContainer. Can I still use the Children from Panel as well?

What is the meaning of [ContentProperty("Children", true)]? The summary explains:

Specifies which property of a class can be interpreted to be the content property when the class is parsed by a XAML processor.

But I am not understanding what he means?

[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 e开发者_C百科mpty collection.
    public UIElementCollection Children { get; }
}

public class Canvas : Panel
{....}

public class MyContainer : Canvas
{

    public MyContainer();

    public ObservableCollection<MyObject> Children {get;}
}


The ContentProperty attribute means that the following two elements are equivalent - the Children property of Canvas is the default content of the Canvas.

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜