ContainerVisual 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
管理 Visual 物件的集合。
public ref class ContainerVisual : System::Windows::Media::Visual
public class ContainerVisual : System.Windows.Media.Visual
type ContainerVisual = class
inherit Visual
Public Class ContainerVisual
Inherits Visual
- 繼承
- 衍生
範例
下列範例示範如何建立物件,該物件會當做兩 DrawingVisual 個 ContainerVisual 物件的父系使用。 新增至 ContainerVisual 物件的物件必須以反向迭置順序新增, (由下到上) ,以確保它們以正確的繪圖順序呈現。 為了讓視覺化樹狀結構正確列舉,此範例會提供方法與 VisualChildrenCount 屬性的 GetVisualChild 覆寫實作。
// Create a host visual derived from the FrameworkElement class.
// This class provides layout, event handling, and container support for
// the child visual objects.
public class MyContainerVisualHost : FrameworkElement
{
private ContainerVisual _containerVisual;
public MyContainerVisualHost(DrawingVisual border, DrawingVisual text)
{
// Create a ContainerVisual to hold DrawingVisual children.
_containerVisual = new ContainerVisual();
// Add children to ContainerVisual in reverse z-order (bottom to top).
_containerVisual.Children.Add(border);
_containerVisual.Children.Add(text);
// Create parent-child relationship with host visual and ContainerVisual.
this.AddVisualChild(_containerVisual);
}
// Provide a required override for the VisualChildrenCount property.
protected override int VisualChildrenCount
{
get { return _containerVisual == null ? 0 : 1; }
}
// Provide a required override for the GetVisualChild method.
protected override Visual GetVisualChild(int index)
{
if (_containerVisual == null)
{
throw new ArgumentOutOfRangeException();
}
return _containerVisual;
}
}
' Create a host visual derived from the FrameworkElement class.
' This class provides layout, event handling, and container support for
' the child visual objects.
Public Class MyContainerVisualHost
Inherits FrameworkElement
Private _containerVisual As ContainerVisual
Public Sub New(ByVal border As DrawingVisual, ByVal text As DrawingVisual)
' Create a ContainerVisual to hold DrawingVisual children.
_containerVisual = New ContainerVisual()
' Add children to ContainerVisual in reverse z-order (bottom to top).
_containerVisual.Children.Add(border)
_containerVisual.Children.Add(text)
' Create parent-child relationship with host visual and ContainerVisual.
Me.AddVisualChild(_containerVisual)
End Sub
' Provide a required override for the VisualChildrenCount property.
Protected Overrides ReadOnly Property VisualChildrenCount() As Integer
Get
Return If(_containerVisual Is Nothing, 0, 1)
End Get
End Property
' Provide a required override for the GetVisualChild method.
Protected Overrides Function GetVisualChild(ByVal index As Integer) As Visual
If _containerVisual Is Nothing Then
Throw New ArgumentOutOfRangeException()
End If
Return _containerVisual
End Function
End Class
備註
類別 ContainerVisual 會當做 物件集合的 Visual 容器使用。 類別 DrawingVisual 衍生自 ContainerVisual 類別,因此 DrawingVisual 類別也可以包含視覺物件的集合。
建構函式
ContainerVisual() |
建立 ContainerVisual 類別的新執行個體。 |