docs.unity3d.com
    Show / Hide Table of Contents

    Class VisualElementExtensions

    Extensions for VisualElement class.

    Inheritance
    Object
    VisualElementExtensions
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.AppUI.UI
    Syntax
    public static class VisualElementExtensions

    Methods

    GetChildren<T>(VisualElement, Boolean)

    Get child elements of a given type.

    Declaration
    public static IEnumerable<T> GetChildren<T>(this VisualElement element, bool recursive)
        where T : VisualElement
    Parameters
    Type Name Description
    VisualElement element

    The parent element.

    Boolean recursive

    If true, the search will be recursive.

    Returns
    Type Description
    IEnumerable<T>

    A list of child elements of the given type.

    Type Parameters
    Name Description
    T

    The type of the child elements to search for.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    GetContext(VisualElement)

    Get the current application context associated with the current VisualElement object.

    Declaration
    public static ApplicationContext GetContext(this VisualElement ve)
    Parameters
    Type Name Description
    VisualElement ve

    The VisualElement object.

    Returns
    Type Description
    ApplicationContext

    The application context for this element.

    Exceptions
    Type Condition
    ArgumentNullException

    The provided VisualElement object must be not null.

    GetContext<T>(VisualElement)

    Get the context of a given type in a VisualElement.

    Declaration
    public static T GetContext<T>(this VisualElement element)
        where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    Returns
    Type Description
    T

    The context.

    Type Parameters
    Name Description
    T

    The type of the context.

    Remarks

    This method will look for the context in the current element and its parents without checking if the element is part of the visual tree.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    GetContextProvider<T>(VisualElement)

    Find the closest context provider in the hierarchy of a VisualElement.

    Declaration
    public static VisualElement GetContextProvider<T>(this VisualElement element)
        where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    Returns
    Type Description
    VisualElement

    The context provider.

    Type Parameters
    Name Description
    T

    The type of the context.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    GetPanelSettings(IPanel)

    Get the PanelSettings instance associated to this IPanel, if any.

    Declaration
    public static PanelSettings GetPanelSettings(this IPanel panel)
    Parameters
    Type Name Description
    IPanel panel

    The IPanel object.

    Returns
    Type Description
    PanelSettings

    The PanelSettings instance if it exists, null otherwise.

    Exceptions
    Type Condition
    ArgumentNullException

    The IPanel object must not be null.

    GetPreferredTooltipPlacement(VisualElement)

    Get the preferred placement for a VisualElement's Tooltip.

    Declaration
    public static PopoverPlacement GetPreferredTooltipPlacement(this VisualElement element)
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement which contains a tooltip.

    Returns
    Type Description
    PopoverPlacement

    The preferred placement, previously set using SetPreferredTooltipPlacement(VisualElement, PopoverPlacement) or the closest value set on a parent ContextProvider element.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    GetSelfContext<T>(VisualElement)

    Get the context of a given type in a VisualElement if this element is provider of this context.

    Declaration
    public static T GetSelfContext<T>(this VisualElement element)
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    Returns
    Type Description
    T

    The context if the element is provider of this context, null otherwise.

    Type Parameters
    Name Description
    T

    The type of the context.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    GetTooltipTemplate(VisualElement)

    Get the tooltip template for a VisualElement.

    Declaration
    public static VisualElement GetTooltipTemplate(this VisualElement element)
    Parameters
    Type Name Description
    VisualElement element

    The target visual element.

    Returns
    Type Description
    VisualElement

    The tooltip template.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    GetWorldBoundingBox(VisualElement)

    Get the world bounding box of a VisualElement.

    Declaration
    public static Rect GetWorldBoundingBox(this VisualElement element)
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    Returns
    Type Description
    Rect

    The world bounding box.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    IsContextProvider<T>(VisualElement)

    Check if a VisualElement provides a context of a given type.

    Declaration
    public static bool IsContextProvider<T>(this VisualElement element)
        where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    Returns
    Type Description
    Boolean

    True if the element provides the context, false otherwise.

    Type Parameters
    Name Description
    T

    The type of the context.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    ProvideContext<T>(VisualElement, T)

    Make the element provide a context of a given type in a VisualElement.

    Declaration
    public static void ProvideContext<T>(this VisualElement element, T context)
        where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    T context

    The context.

    Type Parameters
    Name Description
    T

    The type of the context.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)

    Register a callback to be invoked when the context of a given type changes in a VisualElement.

    Declaration
    public static void RegisterContextChangedCallback<T>(this VisualElement element, EventCallback<ContextChangedEvent<T>> callback)
        where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    UnityEngine.UIElements.EventCallback<ContextChangedEvent<T>> callback

    The callback.

    Type Parameters
    Name Description
    T

    The type of the context.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object and the callback can't be null.

    SetPreferredTooltipPlacement(VisualElement, PopoverPlacement)

    Set a preferred Tooltip placement.

    Declaration
    public static void SetPreferredTooltipPlacement(this VisualElement element, PopoverPlacement placement)
    Parameters
    Type Name Description
    VisualElement element

    The target visual element.

    PopoverPlacement placement

    The placement value.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    SetTooltipTemplate(VisualElement, VisualElement)

    Set the tooltip template for a VisualElement.

    Declaration
    public static void SetTooltipTemplate(this VisualElement element, VisualElement template)
    Parameters
    Type Name Description
    VisualElement element

    The target visual element.

    VisualElement template

    The tooltip template.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)

    Unregister a callback to be invoked when the context of a given type changes in a VisualElement.

    Declaration
    public static void UnregisterContextChangedCallback<T>(this VisualElement element, EventCallback<ContextChangedEvent<T>> callback)
        where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    UnityEngine.UIElements.EventCallback<ContextChangedEvent<T>> callback

    The callback.

    Type Parameters
    Name Description
    T

    The type of the context.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object and the callback can't be null.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023