Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
169 lines (156 sloc) 11.8 KB
<Type Name="ContentPropertyAttribute" FullName="System.Windows.Markup.ContentPropertyAttribute">
<TypeSignature Language="C#" Value="public sealed class ContentPropertyAttribute : Attribute" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit ContentPropertyAttribute extends System.Attribute" />
<TypeSignature Language="DocId" Value="T:System.Windows.Markup.ContentPropertyAttribute" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class ContentPropertyAttribute&#xA;Inherits Attribute" />
<TypeSignature Language="C++ CLI" Value="public ref class ContentPropertyAttribute sealed : Attribute" />
<TypeSignature Language="F#" Value="type ContentPropertyAttribute = class&#xA; inherit Attribute" />
<AssemblyInfo>
<AssemblyName>System.Xaml</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>WindowsBase</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.Attribute</BaseTypeName>
</Base>
<Interfaces />
<Attributes>
<Attribute FrameworkAlternate="netframework-4.8;netcore-3.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2">
<AttributeName>System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8">
<AttributeName>System.Runtime.CompilerServices.TypeForwardedFrom("WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Indicates which property of a type is the XAML content property. A XAML processor uses this information when processing XAML child elements of XAML representations of the attributed type.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If the associated property of a <xref:System.Windows.Markup.ContentPropertyAttribute> is not of type `string` or `object`, a XAML processor attempts to identify a value conversion technique. The first check is for native type conversion, either of the XAML language primitives or of specific native conversions enabled by that particular XAML writer implementation. The next step is to look for a type converter. In the .NET implementations, a type converter is identified based on <xref:System.ComponentModel.TypeConverterAttribute> on either the member level or type level definition that applies. If no value conversion can be identified, a XAML object writer typically throws an exception.
In order to accept more than a single object element as content, the type of the XAML content property must be supportable as a collection type.
Because of the `Inherited=true` declaration of the attribute, a value for a <xref:System.Windows.Markup.ContentPropertyAttribute> normally applies a content property designation to all derived classes as well. Applying an empty <xref:System.Windows.Markup.ContentPropertyAttribute> enables a derived class to remove a declaration of a content property attribute by a base class (and to note that the class has no content property). Applying a differently named <xref:System.Windows.Markup.ContentPropertyAttribute> replaces the inherited <xref:System.Windows.Markup.ContentPropertyAttribute> with the new one.
In previous versions of the .NET Framework, this class existed in the WPF-specific assembly WindowsBase, and also had a parallel implementation in Windows Communication Foundation (WCF). Starting with the .NET Framework 4.0, <xref:System.Windows.Markup.ContentPropertyAttribute> is in the System.Xaml assembly. For more information, see [Types Migrated from WPF to System.Xaml](~/docs/framework/xaml-services/types-migrated-from-wpf-to-system-xaml.md).
## WPF Usage Notes
An example of a class in Windows Presentation Foundation (WPF) that uses the <xref:System.Windows.Markup.ContentPropertyAttribute> is <xref:System.Windows.Controls.ContentControl>, which the <xref:System.Windows.Controls.Button> class inherits from. The <xref:System.Windows.Controls.ContentControl.Content%2A?displayProperty=nameWithType> property is the content property set by the <xref:System.Windows.Markup.ContentPropertyAttribute>. If a <xref:System.Windows.Controls.Button> is instantiated in XAML, the <xref:System.Windows.Controls.ContentControl.Content%2A> of the <xref:System.Windows.Controls.Button> will be set to the element that is between the start and end button tags.
## Examples
The following example creates a class named `Film` that has a <xref:System.Windows.Markup.ContentPropertyAttribute> applied. The property named `Title` is indicated as the content property.
[!code-csharp[MarkupSnippets#MarkupContentPropertyAttribute](~/samples/snippets/csharp/VS_Snippets_Wpf/MarkupSnippets/CSharp/Window1.xaml.cs#markupcontentpropertyattribute)]
[!code-vb[MarkupSnippets#MarkupContentPropertyAttribute](~/samples/snippets/visualbasic/VS_Snippets_Wpf/MarkupSnippets/visualbasic/window1.xaml.vb#markupcontentpropertyattribute)]
]]></format>
</remarks>
<related type="Article" href="https://msdn.microsoft.com/library/5dfb299a-b6e2-41b8-8694-e6ac987547f1">XAML-Related CLR Attributes For Custom Types and Libraries</related>
<related type="Article" href="https://msdn.microsoft.com/library/c2667cbd-2f46-4a7f-9dfc-53696e35e8e4">Defining Custom Types for Use with .NET Framework XAML Services</related>
<related type="Article" href="https://msdn.microsoft.com/library/0e11f386-808c-4eae-9ba6-029ad7ba2211">NET XAML Services Conceptual Documentation</related>
</Docs>
<Members>
<MemberGroup MemberName=".ctor">
<AssemblyInfo>
<AssemblyName>System.Xaml</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Windows.Markup.ContentPropertyAttribute" /> class.</summary>
</Docs>
</MemberGroup>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public ContentPropertyAttribute ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor() cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Markup.ContentPropertyAttribute.#ctor" />
<MemberSignature Language="VB.NET" Value="Public Sub New ()" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; ContentPropertyAttribute();" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xaml</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>WindowsBase</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<Parameters />
<Docs>
<summary>Initializes a new instance of the <see cref="T:System.Windows.Markup.ContentPropertyAttribute" /> class.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Because of the `Inherited=true` declaration of the attribute, a value for a <xref:System.Windows.Markup.ContentPropertyAttribute> normally applies a content property designation to all derived classes as well. Using this signature, or applying an empty <xref:System.Windows.Markup.ContentPropertyAttribute>, enables a derived class to remove a declaration of a content property attribute by a base class (and note that the class has no content property).
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName=".ctor">
<MemberSignature Language="C#" Value="public ContentPropertyAttribute (string name);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string name) cil managed" />
<MemberSignature Language="DocId" Value="M:System.Windows.Markup.ContentPropertyAttribute.#ctor(System.String)" />
<MemberSignature Language="VB.NET" Value="Public Sub New (name As String)" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; ContentPropertyAttribute(System::String ^ name);" />
<MemberSignature Language="F#" Value="new System.Windows.Markup.ContentPropertyAttribute : string -&gt; System.Windows.Markup.ContentPropertyAttribute" Usage="new System.Windows.Markup.ContentPropertyAttribute name" />
<MemberType>Constructor</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xaml</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>WindowsBase</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<Parameters>
<Parameter Name="name" Type="System.String" Index="0" FrameworkAlternate="netframework-4.8" />
</Parameters>
<Docs>
<param name="name">The property name for the property that is the content property.</param>
<summary>Initializes a new instance of the <see cref="T:System.Windows.Markup.ContentPropertyAttribute" /> class, by using the specified name.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Assuming CLR backing, the provided `name` should match the <xref:System.Reflection.MemberInfo.Name%2A?displayProperty=nameWithType> of the relevant property in the CLR type system.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Name">
<MemberSignature Language="C#" Value="public string Name { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance string Name" />
<MemberSignature Language="DocId" Value="P:System.Windows.Markup.ContentPropertyAttribute.Name" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Name As String" />
<MemberSignature Language="C++ CLI" Value="public:&#xA; property System::String ^ Name { System::String ^ get(); };" />
<MemberSignature Language="F#" Value="member this.Name : string" Usage="System.Windows.Markup.ContentPropertyAttribute.Name" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyName>System.Xaml</AssemblyName>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>WindowsBase</AssemblyName>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName>get: System.Runtime.TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.String</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the name of the property that is the content property.</summary>
<value>The name of the property that is the content property.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
</Members>
</Type>
You can’t perform that action at this time.