Export (0) Print
Expand All

ContentPropertyAttribute Class

Specifies which property of a class to use as the content property when written as XAML. This class cannot be inherited.

Namespace: System.Windows.Markup
Assembly: WindowsBase (in windowsbase.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml

'Declaration
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False, Inherited:=True)> _
Public NotInheritable Class ContentPropertyAttribute
	Inherits Attribute
'Usage
Dim instance As ContentPropertyAttribute

/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) */ 
public final class ContentPropertyAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=true) 
public final class ContentPropertyAttribute extends Attribute
 This managed class is not typically used in XAML. 

If the associated property of a ContentPropertyAttribute is not of type string or object, a type converter will be called at runtime. If a type converter cannot be found at runtime, an exception is thrown.

In order to accept more than a single object element as content, the type of the content property must be a collection type.

An example of a class in Windows Presentation Foundation (WPF) that uses the ContentPropertyAttribute is ContentControl, which the Button class inherits from. The property Content on the ContentControl is the content property set by the ContentPropertyAttribute. If a Button is instantiate in XAML, Content of the Button will be set to the element that is between the start and end button tags.

The following example creates a class named Film which is decorated with the ContentPropertyAttribute. The property named Title is set as the content property.

[ContentProperty("Title")]
public class Film
{
    public Film()
    {
    }

    public string Title
    {
        get { return _title; }
        set { _title = value; }
    }

    private string _title;
}

System.Object
   System.Attribute
    System.Windows.Markup.ContentPropertyAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft