System.Windows.Markup 名前空間


.NET Framework クラス ライブラリ
ContentPropertyAttribute クラス

更新 : 2007 年 11 月

XAML として書き込む場合に、クラスのどのプロパティをコンテンツ プロパティとして使用するかを指定します。

名前空間 :  System.Windows.Markup
アセンブリ :  WindowsBase (WindowsBase.dll 内)
XAML の XMLNS : xmlns にマップされていません。

構文

Visual Basic (宣言)
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := False, Inherited := True)> _
Public NotInheritable Class ContentPropertyAttribute _
    Inherits Attribute
Visual Basic (使用法)
Dim instance As ContentPropertyAttribute
C#
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class ContentPropertyAttribute : Attribute
Visual C++
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple = false, Inherited = true)]
public ref class ContentPropertyAttribute sealed : public Attribute
J#
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = false, Inherited = true) */
public final class ContentPropertyAttribute extends Attribute
JScript
public final class ContentPropertyAttribute extends Attribute
XAML
<p>通常、このマネージ クラスは XAML では使用しません。</p>
解説

ContentPropertyAttribute の関連付けられているプロパティが、型文字列またはオブジェクト以外の場合、コンバータが実行時に呼び出されます。型コンバータが実行時に見つからなかった場合は、例外がスローされます。

複数のオブジェクト要素をコンテンツとして受け入れるためには、コンテンツ プロパティの型はコレクション型であることが必要です。

ContentPropertyAttribute を使用する Windows Presentation Foundation (WPF) にあるクラスの例には ContentControl があります。Button クラスは、このクラスを継承します。ContentControl 上のプロパティ Content は、ContentPropertyAttribute によって設定されるコンテンツ プロパティです。Button が XAML でインスタンス化される場合、ButtonContent は開始ボタン タグと終了ボタン タグの間にある要素に設定されます。


次の例では、ContentPropertyAttribute で修飾する Film という名前のクラスを作成します。Title という名前のプロパティは、コンテンツ プロパティとして設定されます。

C#
[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
参照

参照

その他の技術情報

タグ :


Page view tracker