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添加到对象的对象必须以反向 z 顺序添加到顶部 (顶部) ,以确保它们以正确的绘图顺序呈现。 为了使可视化树能够正确枚举,此示例提供重写的方法和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 类的新实例。 |