You can use UQuery to retrieve elements from a visual treeAn object graph, made of lightweight nodes, that holds all the elements in a window or panel. It defines every UI you build with the UI Toolkit.
See in Glossary. UQuery is based on JQuery or Linq, and is designed to limit dynamic memory allocation as much as possible. This allows for optimal performance on mobile platforms.
To use UQuery to retrieve elements, use the UQueryExtensions.Q
or initialize a QueryBuilder
with UQueryExtensions.Query
.
For example, the following UQuery starts at the root and finds the first Button
with the name foo
:
root.Query<Button>("foo").First();
The following UQuery iterates, in the same group, on each Button
named foo
:
root.Query("foo").Children<Button>().ForEach(//do stuff);
Consider the following when you use UQuery:
QueryState
struct (returned by the element.Query()
method) and enumerate it to avoid creating lists. You can also construct a query once and execute it on different elements.VisualElement
class. You can style the look, define the behaviour, and display it on screen as part of the UI. More infoVisualElement
variables inside closures.