Show / Hide Table of Contents

Class SelectableCollectionViewModel<T>

View model class for representing a collection of objects that implements ISelectable. By default it only allows one item to be selected at a time and it will manage the IsSelected property of the items in the collection. If you want to allow multiple selections, set AllowMultipleSelections to true.

Inheritance
object
ViewModelBase
SelectableCollectionViewModel<T>
FilterableListViewModel<T>
SingleSelectListViewModel
Implements
INotifyPropertyChanged
Inherited Members
ViewModelBase.RaisePropertyChanged(string)
ViewModelBase.PropertyChanged
ViewModelBase.HasPropertyChangedSubscriber
ViewModelBase.DebuggingTag
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.Presentation
Assembly: Benday.Presentation.dll
Syntax
public class SelectableCollectionViewModel<T> : ViewModelBase, INotifyPropertyChanged where T : class, ISelectable
Type Parameters
Name Description
T

Constructors

| Edit this page View Source

SelectableCollectionViewModel()

Declaration
public SelectableCollectionViewModel()
| Edit this page View Source

SelectableCollectionViewModel(ObservableCollection<T>)

Initializes a new instance of the SelectableCollectionViewModel class with existing items or an existing ObservableCollection instance.

Declaration
public SelectableCollectionViewModel(ObservableCollection<T> values)
Parameters
Type Name Description
ObservableCollection<T> values
Exceptions
Type Condition
ArgumentNullException
| Edit this page View Source

SelectableCollectionViewModel(ObservableCollection<T>, T)

Initializes a new instance of the SelectableCollectionViewModel class with existing items or an existing ObservableCollection instance.

Declaration
public SelectableCollectionViewModel(ObservableCollection<T> values, T selectedItem)
Parameters
Type Name Description
ObservableCollection<T> values
T selectedItem

Item in the values collection that should be selected

Exceptions
Type Condition
ArgumentNullException

Fields

| Edit this page View Source

ItemsPropertyName

Declaration
public readonly string ItemsPropertyName
Field Value
Type Description
string
| Edit this page View Source

_Items

Declaration
protected ObservableCollection<T> _Items
Field Value
Type Description
ObservableCollection<T>

Properties

| Edit this page View Source

AllowMultipleSelections

Gets or sets a value indicating whether multiple selections are allowed.

Declaration
public bool AllowMultipleSelections { get; set; }
Property Value
Type Description
bool
| Edit this page View Source

BeforeSetSelectedItem

Gets or sets a delegate that is called before the selected item is changed. Return false from the delegate to cancel the selection change.

Declaration
public SelectableCollectionViewModel<T>.BeforeSetSelectedItemDelegate? BeforeSetSelectedItem { get; set; }
Property Value
Type Description
SelectableCollectionViewModel<T>.BeforeSetSelectedItemDelegate
| Edit this page View Source

Count

Gets the number of items in the collection.

Declaration
public int Count { get; }
Property Value
Type Description
int
| Edit this page View Source

HasOnItemSelectedSubscriber

Utility property to determine if the view model has a subscriber to the OnItemSelected event.

Declaration
public bool HasOnItemSelectedSubscriber { get; }
Property Value
Type Description
bool
| Edit this page View Source

IgnoreRequestsToSetNullValuesAsSelected

Gets or sets a value indicating whether requests to set null values as the selected item should be ignored. When true, setting SelectedItem to null will have no effect. Default is false.

Declaration
public bool IgnoreRequestsToSetNullValuesAsSelected { get; set; }
Property Value
Type Description
bool
| Edit this page View Source

IsEnabled

Gets or sets a value indicating whether this view model is enabled.

Declaration
public bool IsEnabled { get; set; }
Property Value
Type Description
bool
| Edit this page View Source

IsValid

Gets or sets a value indicating whether this view model is valid. NOTE: this property does not do any validation, it is just a flag that can be used by the view.

Declaration
public bool IsValid { get; set; }
Property Value
Type Description
bool
| Edit this page View Source

Items

Gets or sets the collection of items.

Declaration
public ObservableCollection<T> Items { get; protected set; }
Property Value
Type Description
ObservableCollection<T>
| Edit this page View Source

SelectedItem

Gets or sets the selected item.

Declaration
public T? SelectedItem { get; set; }
Property Value
Type Description
T

Methods

| Edit this page View Source

Add(T)

Adds an item to the collection.

Declaration
public void Add(T addThis)
Parameters
Type Name Description
T addThis
Exceptions
Type Condition
InvalidOperationException
| Edit this page View Source

Clear()

Clears the collection.

Declaration
public void Clear()
| Edit this page View Source

GetSelectedItems()

Gets the selected items.

Declaration
public List<T> GetSelectedItems()
Returns
Type Description
List<T>

Selected items in a new instance of List

| Edit this page View Source

IndexOf(T)

Returns the index of the specified item in the collection.

Declaration
public int IndexOf(T item)
Parameters
Type Name Description
T item

The item to locate.

Returns
Type Description
int

The zero-based index of the item, or -1 if not found.

| Edit this page View Source

Initialize(IEnumerable<T>)

Resets the collection to the specified values.

Declaration
public virtual void Initialize(IEnumerable<T> values)
Parameters
Type Name Description
IEnumerable<T> values
| Edit this page View Source

Move(int, int)

Moves an item from one position to another in the collection.

Declaration
public void Move(int draggedIndex, int targetIndex)
Parameters
Type Name Description
int draggedIndex

The current index of the item to move.

int targetIndex

The index to move the item to.

| Edit this page View Source

OnAfterMove(int, int)

Raises the AfterMove event.

Declaration
protected virtual void OnAfterMove(int draggedIndex, int targetIndex)
Parameters
Type Name Description
int draggedIndex

The original index of the moved item.

int targetIndex

The new index of the moved item.

| Edit this page View Source

OnItemPropertyChanged(object?, PropertyChangedEventArgs)

Declaration
protected virtual void OnItemPropertyChanged(object? sender, PropertyChangedEventArgs e)
Parameters
Type Name Description
object sender
PropertyChangedEventArgs e
| Edit this page View Source

Remove(T)

Removes an item from the collection.

Declaration
public void Remove(T removeThis)
Parameters
Type Name Description
T removeThis
Exceptions
Type Condition
InvalidOperationException

Events

| Edit this page View Source

AfterMove

Event raised after an item has been moved within the collection.

Declaration
public event EventHandler<MoveEventArgs<T>>? AfterMove
Event Type
Type Description
EventHandler<MoveEventArgs<T>>
| Edit this page View Source

OnItemSelected

Event that is raised when an item is selected.

Declaration
public event ItemSelectedEventHandler<T>? OnItemSelected
Event Type
Type Description
ItemSelectedEventHandler<T>

Implements

INotifyPropertyChanged
  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com