VisualTreeHelper VisualTreeHelper VisualTreeHelper VisualTreeHelper Class

定义

提供一些实用工具方法,用于执行涉及可视化树中的节点的常规任务。Provides utility methods that perform common tasks involving nodes in a visual tree.

public ref class VisualTreeHelper abstract sealed
public static class VisualTreeHelper
type VisualTreeHelper = class
Public Class VisualTreeHelper
继承
VisualTreeHelperVisualTreeHelperVisualTreeHelperVisualTreeHelper

示例

下面的示例演示如何枚举视觉对象的所有后代,如果你对序列化可视化对象层次结构的所有呈现信息感兴趣,则可能希望使用该技术。The following example shows how to enumerate all the descendants of a visual object, which is a technique you might want to use if you were interested in serializing all the rendering information of a visual object hierarchy.

// Enumerate all the descendants of the visual object.
static public void EnumVisual(Visual myVisual)
{
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
    {
        // Retrieve child visual at specified index value.
        Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);

        // Do processing of the child visual object.

        // Enumerate children of the child visual object.
        EnumVisual(childVisual);
    }
}
' Enumerate all the descendants of the visual object.
Public Shared Sub EnumVisual(ByVal myVisual As Visual)
    For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(myVisual) - 1
        ' Retrieve child visual at specified index value.
        Dim childVisual As Visual = CType(VisualTreeHelper.GetChild(myVisual, i), Visual)

        ' Do processing of the child visual object.

        ' Enumerate children of the child visual object.
        EnumVisual(childVisual)
    Next i
End Sub

注解

可视化树中的节点可以是VisualVisual3D对象。Nodes in the visual tree can be either Visual or Visual3D objects. 特定于某种视觉对象类型的方法被类型化为Visual或。 Visual3DMethods that are specific to a type of visual object are typed as either Visual or Visual3D. 但是, 类中的VisualTreeHelper某些方法可以DependencyObject接受表示任一类型的视觉对象的值。However, some methods in the VisualTreeHelper class can accept a DependencyObject value that represents either type of visual object.

WPFWPF支持以编程方式访问对象的多个不同树结构。supports programmatic access to several different tree structures of objects. 这主要是公开为可视化树和逻辑树。Primarily, this is exposed as a visual tree and a logical tree. 在某些情况下, 逻辑树是WPFWPF应用程序中的元素的更实用表示形式, 但从概念上讲, 逻辑树是在Visual类之外的级别实现的。In some cases, the logical tree is a more useful representation of the elements in a WPFWPF application, but conceptually the logical tree is implemented at a level beyond the Visual class. 与可视化树不同, 逻辑树可以表示非可视数据对象, 例如ListItemUnlike the visual tree, the logical tree can represent nonvisual data objects, such as ListItem. 有关逻辑树的详细信息,请参阅 WPF 中的树For more information on the logical tree, see Trees in WPF. 类似的实用工具方法类LogicalTreeHelper还支持逻辑树。The logical tree also is supported by a similar utility method class, LogicalTreeHelper.

方法

GetBitmapEffect(Visual) GetBitmapEffect(Visual) GetBitmapEffect(Visual) GetBitmapEffect(Visual)

返回指定 BitmapEffectVisual 值。Returns the BitmapEffect value for the specified Visual.

GetBitmapEffectInput(Visual) GetBitmapEffectInput(Visual) GetBitmapEffectInput(Visual) GetBitmapEffectInput(Visual)

返回指定 BitmapEffectInputVisual 值。Returns the BitmapEffectInput value for the specified Visual.

GetCacheMode(Visual) GetCacheMode(Visual) GetCacheMode(Visual) GetCacheMode(Visual)

检索指定的 Visual 的缓存表示形式。Retrieves the cached representation of the specified Visual.

GetChild(DependencyObject, Int32) GetChild(DependencyObject, Int32) GetChild(DependencyObject, Int32) GetChild(DependencyObject, Int32)

返回指定父可视对象中位于指定集合索引位置的子可视对象。Returns the child visual object from the specified collection index within a specified parent.

GetChildrenCount(DependencyObject) GetChildrenCount(DependencyObject) GetChildrenCount(DependencyObject) GetChildrenCount(DependencyObject)

返回指定可视对象包含的子级个数。Returns the number of children that the specified visual object contains.

GetClip(Visual) GetClip(Visual) GetClip(Visual) GetClip(Visual)

将指定的 Visual 的剪辑区域作为 Geometry 值返回。Return the clip region of the specified Visual as a Geometry value.

GetContentBounds(Visual3D) GetContentBounds(Visual3D) GetContentBounds(Visual3D) GetContentBounds(Visual3D)

返回指定 Visual3D 的已缓存的边界框矩形。Returns the cached bounding box rectangle for the specified Visual3D.

GetContentBounds(Visual) GetContentBounds(Visual) GetContentBounds(Visual) GetContentBounds(Visual)

返回指定 Visual 的已缓存的边界框矩形。Returns the cached bounding box rectangle for the specified Visual.

GetDescendantBounds(Visual3D) GetDescendantBounds(Visual3D) GetDescendantBounds(Visual3D) GetDescendantBounds(Visual3D)

返回指定 Visual3D 所有子代的所有内容边界框的联合,其中包括 Visual3D 的内容边界框。Returns the union of all the content bounding boxes for all the descendants of the specified Visual3D, which includes the content bounding box of the Visual3D.

GetDescendantBounds(Visual) GetDescendantBounds(Visual) GetDescendantBounds(Visual) GetDescendantBounds(Visual)

返回 Visual 所有子代的所有内容边界框的联合,其中包括 Visual 的内容边界框。Returns the union of all the content bounding boxes for all the descendants of the Visual, which includes the content bounding box of the Visual.

GetDpi(Visual) GetDpi(Visual) GetDpi(Visual) GetDpi(Visual)

获取测量和呈现此视觉对象的 DPI 信息。Gets the DPI information at which this Visual is measured and rendered.

GetDrawing(Visual) GetDrawing(Visual) GetDrawing(Visual) GetDrawing(Visual)

返回指定的 Visual 的绘图内容。Returns the drawing content of the specified Visual.

GetEdgeMode(Visual) GetEdgeMode(Visual) GetEdgeMode(Visual) GetEdgeMode(Visual)

将指定的 Visual 的边缘模式作为 EdgeMode 值返回。Returns the edge mode of the specified Visual as an EdgeMode value.

GetEffect(Visual) GetEffect(Visual) GetEffect(Visual) GetEffect(Visual)

获取指定 Visual 的位图效果。Gets the bitmap effect for the specified Visual.

GetOffset(Visual) GetOffset(Visual) GetOffset(Visual) GetOffset(Visual)

返回 Visual 的偏移量。Returns the offset of the Visual.

GetOpacity(Visual) GetOpacity(Visual) GetOpacity(Visual) GetOpacity(Visual)

返回 Visual 的不透明度。Returns the opacity of the Visual.

GetOpacityMask(Visual) GetOpacityMask(Visual) GetOpacityMask(Visual) GetOpacityMask(Visual)

返回一个 Brush 值,该值表示 Visual 的不透明蒙板。Returns a Brush value that represents the opacity mask of the Visual.

GetParent(DependencyObject) GetParent(DependencyObject) GetParent(DependencyObject) GetParent(DependencyObject)

返回表示视觉对象的父对象的 DependencyObject 值。Returns a DependencyObject value that represents the parent of the visual object.

GetTransform(Visual) GetTransform(Visual) GetTransform(Visual) GetTransform(Visual)

返回 TransformVisual 值。Returns a Transform value for the Visual.

GetXSnappingGuidelines(Visual) GetXSnappingGuidelines(Visual) GetXSnappingGuidelines(Visual) GetXSnappingGuidelines(Visual)

返回 X 坐标(垂直)准线集合。Returns an X-coordinate (vertical) guideline collection.

GetYSnappingGuidelines(Visual) GetYSnappingGuidelines(Visual) GetYSnappingGuidelines(Visual) GetYSnappingGuidelines(Visual)

返回 Y 坐标(水平)准线集合。Returns a Y-coordinate (horizontal) guideline collection.

HitTest(Visual, Point) HitTest(Visual, Point) HitTest(Visual, Point) HitTest(Visual, Point)

通过指定 Point 返回命中测试的最顶层 Visual 对象。Returns the topmost Visual object of a hit test by specifying a Point.

HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D) HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D) HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D) HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D)

使用调用方定义的 HitTestFilterCallbackHitTestResultCallback 方法对指定 Visual3D 启动命中测试。Initiates a hit test on the specified Visual3D, with caller-defined HitTestFilterCallback and HitTestResultCallback methods.

HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters) HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters) HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters) HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

使用调用方定义的 HitTestFilterCallbackHitTestResultCallback 方法对指定 Visual 启动命中测试。Initiates a hit test on the specified Visual, with caller-defined HitTestFilterCallback and HitTestResultCallback methods.

SetRootDpi(Visual, DpiScale) SetRootDpi(Visual, DpiScale) SetRootDpi(Visual, DpiScale) SetRootDpi(Visual, DpiScale)

更新视觉对象的 DPI 信息。Updates the DPI information of a Visual. 它仅能在没有父级的视觉对象上调用。It can only be called on a Visual without a parent.

适用于