更新 : 2007 年 11 月
XAML として書き込む場合に、クラスのどのプロパティをコンテンツ プロパティとして使用するかを指定します。
名前空間 :
System.Windows.Markup アセンブリ :
WindowsBase (WindowsBase.dll 内)
XAML の XMLNS : xmlns にマップされていません。
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := False, Inherited := True)> _
Public NotInheritable Class ContentPropertyAttribute _
Inherits Attribute
Dim instance As ContentPropertyAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class ContentPropertyAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple = false, Inherited = true)]
public ref class ContentPropertyAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false, Inherited = true) */
public final class ContentPropertyAttribute extends Attribute
public final class ContentPropertyAttribute extends Attribute
<p>通常、このマネージ クラスは XAML では使用しません。</p>
ContentPropertyAttribute の関連付けられているプロパティが、型文字列またはオブジェクト以外の場合、コンバータが実行時に呼び出されます。型コンバータが実行時に見つからなかった場合は、例外がスローされます。
複数のオブジェクト要素をコンテンツとして受け入れるためには、コンテンツ プロパティの型はコレクション型であることが必要です。
ContentPropertyAttribute を使用する Windows Presentation Foundation (WPF) にあるクラスの例には ContentControl があります。Button クラスは、このクラスを継承します。ContentControl 上のプロパティ Content は、ContentPropertyAttribute によって設定されるコンテンツ プロパティです。Button が XAML でインスタンス化される場合、Button の Content は開始ボタン タグと終了ボタン タグの間にある要素に設定されます。
次の例では、ContentPropertyAttribute で修飾する Film という名前のクラスを作成します。Title という名前のプロパティは、コンテンツ プロパティとして設定されます。
[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
この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
Windows Vista
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
.NET Framework
サポート対象 : 3.5、3.0
参照
その他の技術情報