Class VisualElementExtensions
Extensions for Visual
Inherited Members
Namespace: Unity.AppUI .UI
Assembly: Unity.AppUI.dll
Syntax
public static class VisualElementExtensions
Methods
EnablePicking(VisualElement, bool)
Set the picking mode of a Visual
Declaration
public static void EnablePicking(this VisualElement element, bool enabled)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
bool | enabled | True to enable picking, false otherwise. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
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 |
---|---|---|
Visual |
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 |
---|---|
Argument |
The Visual |
GetContextProvider<T>(VisualElement)
Find the closest context provider in the hierarchy of a Visual
Declaration
public static VisualElement GetContextProvider<T>(this VisualElement element) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
Returns
Type | Description |
---|---|
Visual |
The context provider. |
Type Parameters
Name | Description |
---|---|
T | The type of the context. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
GetContextProvider<T>(VisualElement, string)
Find the closest context provider in the hierarchy of a Visual
Declaration
public static VisualElement GetContextProvider<T>(this VisualElement element, string key) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
string | key | The key to identify the context. |
Returns
Type | Description |
---|---|
Visual |
The context provider. |
Type Parameters
Name | Description |
---|---|
T | The type of the context. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
GetContext<T>(VisualElement)
Get the context of a given type in a Visual
Declaration
public static T GetContext<T>(this VisualElement element) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 |
---|---|
Argument |
The Visual |
GetContext<T>(VisualElement, string)
Get the context of a given type in a Visual
Declaration
public static T GetContext<T>(this VisualElement element, string key) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 |
---|---|
Argument |
The Visual |
GetExclusiveRootElement(VisualElement)
Retrieve the root element of a Visual
Declaration
public static VisualElement GetExclusiveRootElement(this VisualElement element)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
Returns
Type | Description |
---|---|
Visual |
The root element of the visual tree. |
GetPreferredTooltipPlacement(VisualElement)
Get the preferred placement for a Visual
Declaration
public static PopoverPlacement GetPreferredTooltipPlacement(this VisualElement element)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
Returns
Type | Description |
---|---|
Popover |
The preferred placement, previously set using Set |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
GetSelfContext<T>(VisualElement)
Get the context of a given type in a Visual
Declaration
public static T GetSelfContext<T>(this VisualElement element)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 |
---|---|
Argument |
The Visual |
GetSelfContext<T>(VisualElement, string)
Get the context of a given type in a Visual
Declaration
public static T GetSelfContext<T>(this VisualElement element, string key)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 |
---|---|
Argument |
The Visual |
GetTooltipContent(VisualElement)
Get the tooltip content for a Visual
Declaration
public static VisualElementExtensions.TooltipContentCallback GetTooltipContent(this VisualElement element)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The target visual element. |
Returns
Type | Description |
---|---|
Visual |
The tooltip content callback. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
GetTooltipTemplate(VisualElement)
Get the tooltip template for a Visual
Declaration
public static VisualElement GetTooltipTemplate(this VisualElement element)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The target visual element. |
Returns
Type | Description |
---|---|
Visual |
The tooltip template. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
IsContextProvider<T>(VisualElement)
Check if a Visual
Declaration
public static bool IsContextProvider<T>(this VisualElement element) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 |
---|---|
Argument |
The Visual |
IsContextProvider<T>(VisualElement, string)
Check if a Visual
Declaration
public static bool IsContextProvider<T>(this VisualElement element, string key) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 |
---|---|
Argument |
The Visual |
IsInvisible(VisualElement)
Check if a Visual
Declaration
public static bool IsInvisible(this VisualElement element)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 is set to Hidden, has an opacity lower than 0.001 or has a display style set to None.
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
IsOnScreen(VisualElement)
Check if a Visual
Declaration
public static bool IsOnScreen(this VisualElement element)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
Returns
Type | Description |
---|---|
bool | True if the element is on screen, false otherwise. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
ProvideContext<T>(VisualElement, string, T)
Make the element provide a context of a given type in a Visual
Declaration
public static void ProvideContext<T>(this VisualElement element, string key, T context) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
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 |
---|---|
Argument |
The Visual |
ProvideContext<T>(VisualElement, T)
Make the element provide a context of a given type in a Visual
Declaration
public static void ProvideContext<T>(this VisualElement element, T context) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
T | context | The context. |
Type Parameters
Name | Description |
---|---|
T | The type of the context. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
RegisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
Register a callback to be invoked when the context of a given type changes in a Visual
Declaration
public static void RegisterContextChangedCallback<T>(this VisualElement element, string key, EventCallback<ContextChangedEvent<T>> callback) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
string | key | The key used to identify the context. |
Event |
callback | The callback. |
Type Parameters
Name | Description |
---|---|
T | The type of the context. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
RegisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
Register a callback to be invoked when the context of a given type changes in a Visual
Declaration
public static void RegisterContextChangedCallback<T>(this VisualElement element, EventCallback<ContextChangedEvent<T>> callback) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
Event |
callback | The callback. |
Type Parameters
Name | Description |
---|---|
T | The type of the context. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
SetPreferredTooltipPlacement(VisualElement, OptionalEnum<PopoverPlacement>)
Set a preferred Tooltip placement.
Declaration
public static void SetPreferredTooltipPlacement(this VisualElement element, OptionalEnum<PopoverPlacement> placement)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The target visual element. |
Optional |
placement | The placement value. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
SetTooltipContent(VisualElement, TooltipContentCallback)
Set the tooltip content for a Visual
Declaration
public static void SetTooltipContent(this VisualElement element, VisualElementExtensions.TooltipContentCallback callback)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The target visual element. |
Visual |
callback | The callback to invoke to populate the tooltip. |
Remarks
You must call Set
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
Invalid |
You must call SetTooltipTemplate before setting the tooltip content. |
SetTooltipTemplate(VisualElement, VisualElement)
Set the tooltip template for a Visual
Declaration
public static void SetTooltipTemplate(this VisualElement element, VisualElement template)
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The target visual element. |
Visual |
template | The tooltip template. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
UnregisterContextChangedCallback<T>(VisualElement, string, EventCallback<ContextChangedEvent<T>>)
Unregister a callback to be invoked when the context of a given type changes in a Visual
Declaration
public static void UnregisterContextChangedCallback<T>(this VisualElement element, string key, EventCallback<ContextChangedEvent<T>> callback) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
string | key | The key used to identify the context. |
Event |
callback | The callback. |
Type Parameters
Name | Description |
---|---|
T | The type of the context. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |
UnregisterContextChangedCallback<T>(VisualElement, EventCallback<ContextChangedEvent<T>>)
Unregister a callback to be invoked when the context of a given type changes in a Visual
Declaration
public static void UnregisterContextChangedCallback<T>(this VisualElement element, EventCallback<ContextChangedEvent<T>> callback) where T : IContext
Parameters
Type | Name | Description |
---|---|---|
Visual |
element | The Visual |
Event |
callback | The callback. |
Type Parameters
Name | Description |
---|---|
T | The type of the context. |
Exceptions
Type | Condition |
---|---|
Argument |
The Visual |