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. 與視覺化樹狀結構不同的是, 邏輯樹狀結構可以代表非視覺化的ListItem資料物件, 例如。Unlike 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)

取得測量及轉譯此 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)

更新 Visual 的 DPI 的資訊。Updates the DPI information of a Visual. 它只能在不具父代的 Visual 上呼叫。It can only be called on a Visual without a parent.

適用於