Class SelectingItemsControl
- Namespace
- Avalonia.Controls.Primitives
- Assembly
- Avalonia.Controls.dll
An ItemsControl that maintains a selection.
public class SelectingItemsControl : ItemsControl, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IChildIndexProvider
- Inheritance
-
SelectingItemsControl
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
SelectingItemsControl provides a base class for ItemsControls that maintain a selection (single or multiple). By default only its SelectedIndex and SelectedItem properties are visible; the current multiple Selection and SelectedItems together with the SelectionMode properties are protected, however a derived class can expose these if it wishes to support multiple selection.
SelectingItemsControl maintains a selection respecting the current SelectionMode but it does not react to user input; this must be handled in a derived class. It does, however, respond to IsSelectedChangedEvent events from items and updates the selection accordingly.
Constructors
SelectingItemsControl()
public SelectingItemsControl()
Fields
AutoScrollToSelectedItemProperty
Defines the AutoScrollToSelectedItem property.
public static readonly StyledProperty<bool> AutoScrollToSelectedItemProperty
Field Value
IsSelectedChangedEvent
Event that should be raised by containers when their selection state changes to notify the parent SelectingItemsControl that their selection state has changed.
public static readonly RoutedEvent<RoutedEventArgs> IsSelectedChangedEvent
Field Value
IsSelectedProperty
Defines the IsSelected attached property.
public static readonly StyledProperty<bool> IsSelectedProperty
Field Value
IsTextSearchEnabledProperty
Defines the IsTextSearchEnabled property.
public static readonly StyledProperty<bool> IsTextSearchEnabledProperty
Field Value
SelectedIndexProperty
Defines the SelectedIndex property.
public static readonly DirectProperty<SelectingItemsControl, int> SelectedIndexProperty
Field Value
SelectedItemProperty
Defines the SelectedItem property.
public static readonly DirectProperty<SelectingItemsControl, object?> SelectedItemProperty
Field Value
SelectedItemsProperty
Defines the SelectedItems property.
protected static readonly DirectProperty<SelectingItemsControl, IList?> SelectedItemsProperty
Field Value
SelectedValueBindingProperty
Defines the SelectedValueBinding property
public static readonly StyledProperty<IBinding?> SelectedValueBindingProperty
Field Value
SelectedValueProperty
Defines the SelectedValue property
public static readonly StyledProperty<object?> SelectedValueProperty
Field Value
SelectionChangedEvent
Defines the SelectionChanged event.
public static readonly RoutedEvent<SelectionChangedEventArgs> SelectionChangedEvent
Field Value
SelectionModeProperty
Defines the SelectionMode property.
protected static readonly StyledProperty<SelectionMode> SelectionModeProperty
Field Value
SelectionProperty
Defines the Selection property.
protected static readonly DirectProperty<SelectingItemsControl, ISelectionModel> SelectionProperty
Field Value
WrapSelectionProperty
Defines the WrapSelection property.
public static readonly StyledProperty<bool> WrapSelectionProperty
Field Value
Properties
AlwaysSelected
Gets a value indicating whether AlwaysSelected is set.
protected bool AlwaysSelected { get; }
Property Value
AutoScrollToSelectedItem
Gets or sets a value indicating whether to automatically scroll to newly selected items.
public bool AutoScrollToSelectedItem { get; set; }
Property Value
IsTextSearchEnabled
Gets or sets a value that specifies whether a user can jump to a value by typing.
public bool IsTextSearchEnabled { get; set; }
Property Value
SelectedIndex
Gets or sets the index of the selected item.
public int SelectedIndex { get; set; }
Property Value
SelectedItem
Gets or sets the selected item.
public object? SelectedItem { get; set; }
Property Value
SelectedItems
Gets or sets the selected items.
protected IList? SelectedItems { get; set; }
Property Value
Remarks
By default returns a collection that can be modified in order to manipulate the control selection, however this property will return null if Selection is re-assigned; you should only use either Selection or SelectedItems.
SelectedValue
Gets or sets the value of the selected item, obtained using SelectedValueBinding
public object? SelectedValue { get; set; }
Property Value
SelectedValueBinding
Gets the IBinding instance used to obtain the SelectedValue property
[AssignBinding]
[InheritDataTypeFromItems("ItemsSource")]
public IBinding? SelectedValueBinding { get; set; }
Property Value
Selection
Gets or sets the model that holds the current selection.
protected ISelectionModel Selection { get; set; }
Property Value
SelectionMode
Gets or sets the selection mode.
protected SelectionMode SelectionMode { get; set; }
Property Value
Remarks
Note that the selection mode only applies to selections made via user interaction. Multiple selections can be made programmatically regardless of the value of this property.
WrapSelection
Gets or sets a value which indicates whether to wrap around when the first or last item is reached.
public bool WrapSelection { get; set; }
Property Value
Methods
BeginInit()
public override void BeginInit()
ClearContainerForItemOverride(Control)
Undoes the effects of the PrepareContainerForItemOverride(Control, object?, int) method.
protected override void ClearContainerForItemOverride(Control element)
Parameters
element
Control
ContainerForItemPreparedOverride(Control, object?, int)
Called when a container has been fully prepared to display an item.
protected override void ContainerForItemPreparedOverride(Control container, object? item, int index)
Parameters
container
ControlThe container control.
item
objectThe item being displayed.
index
intThe index of the item being displayed.
Remarks
This method will be called when a container has been fully prepared and added to the logical and visual trees, but may be called before a layout pass has completed. It is called immediately before the ContainerPrepared event is raised.
ContainerIndexChangedOverride(Control, int, int)
Called when the index for a container changes due to an insertion or removal in the items collection.
protected override void ContainerIndexChangedOverride(Control container, int oldIndex, int newIndex)
Parameters
container
ControlThe container whose index changed.
oldIndex
intThe old index.
newIndex
intThe new index.
EndInit()
public override void EndInit()
GetContainerFromEventSource(object?)
Tries to get the container that was the source of an event.
protected Control? GetContainerFromEventSource(object? eventSource)
Parameters
eventSource
objectThe control that raised the event.
Returns
- Control
The container or null if the event did not originate in a container.
GetIsSelected(Control)
Gets the value of the IsSelectedProperty on the specified control.
public static bool GetIsSelected(Control control)
Parameters
control
ControlThe control.
Returns
- bool
The value of the attached property.
MoveSelection(Control?, NavigationDirection, bool, bool)
Moves the selection in the specified direction relative to the specified container.
protected bool MoveSelection(Control? from, NavigationDirection direction, bool wrap = false, bool rangeModifier = false)
Parameters
from
ControlThe container which serves as a starting point for the movement.
direction
NavigationDirectionThe direction to move.
wrap
boolWhether to wrap when the selection reaches the first or last item.
rangeModifier
boolWhether the range modifier is enabled (i.e. shift key).
Returns
- bool
True if the selection was moved; otherwise false.
MoveSelection(NavigationDirection, bool, bool)
Moves the selection in the specified direction relative to the current selection.
protected bool MoveSelection(NavigationDirection direction, bool wrap = false, bool rangeModifier = false)
Parameters
direction
NavigationDirectionThe direction to move.
wrap
boolWhether to wrap when the selection reaches the first or last item.
rangeModifier
boolWhether the range modifier is enabled (i.e. shift key).
Returns
- bool
True if the selection was moved; otherwise false.
OnApplyTemplate(TemplateAppliedEventArgs)
Called when the control's template is applied. In simple terms, this means the method is called just before the control is displayed.
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
Parameters
e
TemplateAppliedEventArgsThe event args.
OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is added to a rooted visual tree.
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
e
VisualTreeAttachmentEventArgsThe event args.
OnDataContextBeginUpdate()
Called when the DataContext begins updating.
protected override void OnDataContextBeginUpdate()
OnDataContextEndUpdate()
Called when the DataContext finishes updating.
protected override void OnDataContextEndUpdate()
OnInitialized()
Called when the control finishes initialization.
protected override void OnInitialized()
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
change
AvaloniaPropertyChangedEventArgsThe property change details.
OnTextInput(TextInputEventArgs)
Called before the TextInput event occurs.
protected override void OnTextInput(TextInputEventArgs e)
Parameters
e
TextInputEventArgsThe event args.
PrepareContainerForItemOverride(Control, object?, int)
Prepares the specified element to display the specified item.
protected override void PrepareContainerForItemOverride(Control container, object? item, int index)
Parameters
container
ControlThe element that's used to display the specified item.
item
objectThe item to display.
index
intThe index of the item to display.
SetIsSelected(Control, bool)
Gets the value of the IsSelectedProperty on the specified control.
public static void SetIsSelected(Control control, bool value)
Parameters
UpdateDataValidation(AvaloniaProperty, BindingValueType, Exception?)
Called to update the validation state for properties for which data validation is enabled.
protected override void UpdateDataValidation(AvaloniaProperty property, BindingValueType state, Exception? error)
Parameters
property
AvaloniaPropertyThe property.
state
BindingValueTypeThe current data binding state.
error
ExceptionThe current data binding error, if any.
UpdateSelection(Control, bool, bool, bool, bool, bool)
Updates the selection for a container based on user interaction.
protected void UpdateSelection(Control container, bool select = true, bool rangeModifier = false, bool toggleModifier = false, bool rightButton = false, bool fromFocus = false)
Parameters
container
ControlThe container.
select
boolWhether the container should be selected or unselected.
rangeModifier
boolWhether the range modifier is enabled (i.e. shift key).
toggleModifier
boolWhether the toggle modifier is enabled (i.e. ctrl key).
rightButton
boolWhether the event is a right-click.
fromFocus
boolWheter the event is a focus event
UpdateSelection(int, bool, bool, bool, bool, bool)
Updates the selection for an item based on user interaction.
protected void UpdateSelection(int index, bool select = true, bool rangeModifier = false, bool toggleModifier = false, bool rightButton = false, bool fromFocus = false)
Parameters
index
intThe index of the item.
select
boolWhether the item should be selected or unselected.
rangeModifier
boolWhether the range modifier is enabled (i.e. shift key).
toggleModifier
boolWhether the toggle modifier is enabled (i.e. ctrl key).
rightButton
boolWhether the event is a right-click.
fromFocus
boolWheter the event is a focus event
UpdateSelectionFromEventSource(object?, bool, bool, bool, bool, bool)
Updates the selection based on an event that may have originated in a container that belongs to the control.
protected bool UpdateSelectionFromEventSource(object? eventSource, bool select = true, bool rangeModifier = false, bool toggleModifier = false, bool rightButton = false, bool fromFocus = false)
Parameters
eventSource
objectThe control that raised the event.
select
boolWhether the container should be selected or unselected.
rangeModifier
boolWhether the range modifier is enabled (i.e. shift key).
toggleModifier
boolWhether the toggle modifier is enabled (i.e. ctrl key).
rightButton
boolWhether the event is a right-click.
fromFocus
boolWheter the event is a focus event
Returns
- bool
True if the event originated from a container that belongs to the control; otherwise false.
Events
SelectionChanged
Occurs when the control's selection changes.
public event EventHandler<SelectionChangedEventArgs>? SelectionChanged