docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class VisualElementExtensions

    Extensions for VisualElement class.

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

    Methods

    EnableDynamicTransform(VisualElement, bool)

    Set UsageHint on a VisualElement.

    Declaration
    public static void EnableDynamicTransform(this VisualElement element, bool enabled)
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    bool enabled

    True to set the UsageHint to Dynamic, false to set it to Static.

    EnablePicking(VisualElement, bool)

    Set the picking mode of a VisualElement.

    Declaration
    public static void EnablePicking(this VisualElement element, bool enabled)
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    bool enabled

    True to enable picking, false otherwise.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    GetChildren<T>(VisualElement, bool)

    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.

    bool 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.

    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.

    GetContextProvider<T>(VisualElement, string)

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

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

    The VisualElement object.

    string key

    The key to identify the context.

    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.

    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.

    GetContext<T>(VisualElement, string)

    Get the context of a given type in a VisualElement.

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

    The VisualElement object.

    string key

    The key to identify the context.

    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.

    GetExclusiveRootElement(VisualElement)

    Retrieve the root element of a VisualElement in the current visual tree that is exclusive to this tree. In Runtime panel context, this is the root of the panel's visual tree directly. In Editor context, tabbed Editor windows share the same root container, so this method will return the child of the root container that is exclusive to this tree and will exclude any IMGUIContainer.

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

    The VisualElement object.

    Returns
    Type Description
    VisualElement

    The root element of the visual tree.

    GetLastAncestorOfType<T>(VisualElement)

    Get the last ancestor of a given type.

    Declaration
    public static T GetLastAncestorOfType<T>(this VisualElement view) where T : VisualElement
    Parameters
    Type Name Description
    VisualElement view

    The VisualElement object.

    Returns
    Type Description
    T

    The last ancestor of the given type.

    Type Parameters
    Name Description
    T

    The type of the ancestor to search for.

    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, OptionalEnum<PopoverPlacement>) or the closest value set on an 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.

    GetSelfContext<T>(VisualElement, string)

    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, string key)
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    string key

    The key used to identify the context.

    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.

    GetTooltipContent(VisualElement)

    Get the tooltip content for a VisualElement.

    Declaration
    public static VisualElementExtensions.TooltipContentCallback GetTooltipContent(this VisualElement element)
    Parameters
    Type Name Description
    VisualElement element

    The target visual element.

    Returns
    Type Description
    VisualElementExtensions.TooltipContentCallback

    The tooltip content callback.

    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.

    HasAncestorsOfType<T>(VisualElement)

    Check if a VisualElement has multiple ancestors of a given type.

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

    The VisualElement object.

    Returns
    Type Description
    bool

    True if the element has multiple ancestors of the given type, false otherwise.

    Type Parameters
    Name Description
    T

    The type of the ancestor to search for.

    Remarks

    This will not include the element itself in the search.

    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
    bool

    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.

    IsContextProvider<T>(VisualElement, string)

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

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

    The VisualElement object.

    string key

    The key used to identify the context.

    Returns
    Type Description
    bool

    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.

    IsInvisible(VisualElement)

    Check if a VisualElement is invisible.

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

    The VisualElement object.

    Returns
    Type Description
    bool

    True if the element is invisible, false otherwise.

    Remarks

    An element is considered invisible if it's not attached to a panel, its visibility attribute or the one from its ancestors is set to Hidden, has a computed opacity value lower than 0.001 or has a display style (itself or ancestors) set to None.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    IsOnScreen(VisualElement)

    Check if a VisualElement is on screen.

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

    The VisualElement object.

    Returns
    Type Description
    bool

    True if the element is on screen, false otherwise.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    ProvideContext<T>(VisualElement, string, T)

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

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

    The VisualElement object.

    string key

    The key to identify the context.

    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.

    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, string, 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, string key, EventCallback<ContextChangedEvent<T>> callback) where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    string key

    The key used to identify the context.

    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.

    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.

    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, OptionalEnum<PopoverPlacement>)

    Set a preferred Tooltip placement.

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

    The target visual element.

    OptionalEnum<PopoverPlacement> placement

    The placement value.

    Exceptions
    Type Condition
    ArgumentNullException

    The VisualElement object can't be null.

    SetTooltipContent(VisualElement, TooltipContentCallback)

    Set the tooltip content for a VisualElement.

    Declaration
    public static void SetTooltipContent(this VisualElement element, VisualElementExtensions.TooltipContentCallback callback)
    Parameters
    Type Name Description
    VisualElement element

    The target visual element.

    VisualElementExtensions.TooltipContentCallback callback

    The callback to invoke to populate the tooltip.

    Remarks

    You must call SetTooltipTemplate(VisualElement, VisualElement) method first in order to have a valid tooltip template to populate.

    Exceptions
    Type Condition
    ArgumentNullException

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

    InvalidOperationException

    You must call SetTooltipTemplate before setting the tooltip content.

    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, string, 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, string key, EventCallback<ContextChangedEvent<T>> callback) where T : IContext
    Parameters
    Type Name Description
    VisualElement element

    The VisualElement object.

    string key

    The key used to identify the context.

    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.

    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.

    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.

    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)