Class ActionBar
A contextual action bar that appears when items are selected in a collection view.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class ActionBar : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder
Remarks
The ActionBar is a UI component that provides contextual actions for selected items in a collection view. It appears when one or more items are selected and offers a way to perform bulk operations on the selected items.
The component consists of three main parts:
- A checkbox for selecting/deselecting all items
- A message indicating the number of selected items
- An action group containing buttons for operations on selected items
The ActionBar integrates seamlessly with Unity's CollectionView components and automatically updates its state based on selection changes.
Examples
Basic usage with ListView:
Connecting an ActionBar with a ListView and adding action buttons.
<UXML>
<ActionBar name="my-action-bar">
<ActionButton icon="edit" label="Edit" />
<ActionButton icon="delete" label="Delete" />
</ActionBar>
<ListView name="my-list-view" selection-type="Multiple" />
<Script>
var actionBar = root.Q<ActionBar>("my-action-bar");
var listView = root.Q<ListView>("my-list-view");
actionBar.collectionView = listView;
</Script>
Customizing the selection message:
Different ways to customize the selection message.
actionBar.message = "{itemCount} items selected - Choose an action below";
// Using smart string for different counts
actionBar.message = "{itemCount:plural:Select items|One item selected| items selected}";
Handling action button clicks:
Adding an action button with click handling for selected items.
var deleteButton = new ActionButton("delete", () => {
var selectedItems = actionBar.selectedIndices.ToList();
// Handle deletion of selected items
});
actionBar.Add(deleteButton);
Constructors
ActionBar()
Default constructor.
Declaration
public ActionBar()
Fields
actionGroupUssClassName
The ActionBar action group styling class.
Declaration
public const string actionGroupUssClassName = "appui-actionbar__actiongroup"
Field Value
| Type | Description |
|---|---|
| string |
checkboxUssClassName
The ActionBar checkbox styling class.
Declaration
public const string checkboxUssClassName = "appui-actionbar__checkbox"
Field Value
| Type | Description |
|---|---|
| string |
labelUssClassName
The ActionBar label styling class.
Declaration
public const string labelUssClassName = "appui-actionbar__label"
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The ActionBar main styling class.
Declaration
public const string ussClassName = "appui-actionbar"
Field Value
| Type | Description |
|---|---|
| string |
Properties
collectionView
The collection view attached to this ActionBar.
Declaration
[Tooltip("The collection view attached to this ActionBar. The collection view is used to get the selected indices and the items source.")]
[CreateProperty]
public BaseVerticalCollectionView collectionView { get; set; }
Property Value
| Type | Description |
|---|---|
| BaseVerticalCollectionView |
contentContainer
The content container of the ActionBar.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
itemsSource
The items source from the Collection View.
Declaration
[CreateProperty(ReadOnly = true)]
public IList itemsSource { get; }
Property Value
| Type | Description |
|---|---|
| IList |
message
Text used for item selection message.
Declaration
[Tooltip("Text used for item selection message.\n\nWe recommend to use a SmartString text in order to adjust the text based on the number of selected items.\nExample: {itemCount:plural:Nothing selected|One selected item|{} selected items}")]
[CreateProperty]
[UxmlAttribute]
[Header("Action Bar")]
public string message { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
We recommend to use a SmartString text in order to adjust the text based on the number of selected items.
Examples
{itemCount:plural:Nothing selected|One selected item|{} selected items}
selectedIndices
The list of selected indices from the Collection View.
Declaration
[CreateProperty(ReadOnly = true)]
public IEnumerable<int> selectedIndices { get; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<int> |