FrameworkElement.GetVisualChild(Int32) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
GetVisualChild(Int32)オーバーライドし、子要素のコレクションから指定したインデックス位置にある子を返します。
protected:
override System::Windows::Media::Visual ^ GetVisualChild(int index);
protected override System.Windows.Media.Visual GetVisualChild(int index);
override this.GetVisualChild : int -> System.Windows.Media.Visual
Protected Overrides Function GetVisualChild (index As Integer) As Visual
パラメーター
- index
- Int32
コレクション内の要求された子要素の 0 から始まるインデックス。
返品
要求された子要素。 これは nullを返すべきではありません。指定されたインデックスが範囲外の場合は、例外がスローされます。
例
次の例は、カスタム装飾が複数のビジュアルの子に対して保持する VisualCollection によって宣言された値を使用する方法を示しています。 これらの値は、 VisualChildrenCount と GetVisualChildのオーバーライドによって報告されます。
// To store and manage the adorner's visual children.
VisualCollection visualChildren;
' To store and manage the adorner's visual children.
Private visualChildren As VisualCollection
// Override the VisualChildrenCount and GetVisualChild properties to interface with
// the adorner's visual collection.
protected override int VisualChildrenCount { get { return visualChildren.Count; } }
protected override Visual GetVisualChild(int index) { return visualChildren[index]; }
' Override the VisualChildrenCount and GetVisualChild properties to interface with
' the adorner's visual collection.
Protected Overrides ReadOnly Property VisualChildrenCount() As Integer
Get
Return visualChildren.Count
End Get
End Property
Protected Overrides Function GetVisualChild(ByVal index As Integer) As Visual
Return visualChildren(index)
End Function
注釈
FrameworkElement実装では、有効なインデックスは 0 のみです。 GetVisualChildのコンテンツ モデルでは、コレクションではなく、0 個または 1 つの子要素がサポートされます。
注意 (継承者)
この実装は、視覚的な子要素のよりわかりやすいコレクションを保持しない要素に対してのみ有効です。 このようなコレクションを持つ要素は、このメソッドをオーバーライドし、その要素でサポートされている子要素コレクション内の同等のインデックスにインデックスをマップする必要があります。 0 から VisualChildrenCount (マイナス 1) の範囲のインデックスは有効な要素を返す必要があります。他のインデックスは範囲外の例外をスローする必要があります。 子コレクションをサポートし、 GetVisualChild(Int32) をオーバーライドして複数の可能な子を返す要素型の例が Panel。
FrameworkElementの既定の実装では、1 つのビジュアル子のみが想定されます。 0 以外の index に渡された値を指定すると、例外がスローされます。 デコレーター、装飾、特殊なレンダリングを持つ要素など、いくつかの一般的な要素は、(中間基底クラスからの実装の) FrameworkElement 実装をオーバーライドします。 一部の実装では引き続き 1 つのビジュアル子が適用されますが、他の実装ではコレクションが許可されます。