views:

23

answers:

1

Hi Guys,

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 empty collection.
    public UIElementCollection Children { get; }
}

public class Canvas : Panel
{....}

public class MyContainer : Canvas
{

    public MyContainer();

    public ObservableCollection<MyObject> Children {get;}
}
+1  A: 

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>
Michael S. Scherotter