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>
SingleSelectListViewModel
Implements
INotifyPropertyChanged
Inherited Members
ViewModelBase.RaisePropertyChanged(string)
ViewModelBase.PropertyChanged
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

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

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

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

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

RefreshSelectedItem(bool)

Declaration
protected void RefreshSelectedItem(bool directAssign = false)
Parameters
Type Name Description
bool directAssign
| 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

OnItemSelected

Event that is raised when an item is selected.

Declaration
public event EventHandler? OnItemSelected
Event Type
Type Description
EventHandler

Implements

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