Class CategoryCollection
- Namespace
- Tudormobile.OpenTrivia.UI.ViewModels
- Assembly
- Tudormobile.OpenTrivia.UI.dll
Represents an observable collection of selectable trivia categories that tracks and exposes the current selection state.
public class CategoryCollection : ObservableCollection<SelectableCategory>, IList<SelectableCategory>, ICollection<SelectableCategory>, IList, ICollection, IReadOnlyList<SelectableCategory>, IReadOnlyCollection<SelectableCategory>, IEnumerable<SelectableCategory>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
- Inheritance
-
CategoryCollection
- Implements
- Inherited Members
Remarks
This collection is designed to manage a set of trivia categories, allowing clients to observe changes in both the collection itself and the selection state of individual categories. It provides convenient access to the currently selected categories and automatically updates observers when the selection changes. This class is suitable for scenarios where the UI or other components need to react to changes in category selection, such as in trivia or quiz applications.
Constructors
CategoryCollection(IEnumerable<TriviaCategory>)
Initializes a new instance of the CategoryCollection class with the specified collection of trivia categories.
public CategoryCollection(IEnumerable<TriviaCategory> categories)
Parameters
categoriesIEnumerable<TriviaCategory>The collection of trivia categories to initialize the collection with.
Properties
SelectedCategories
Gets the collection of categories that are currently selected.
public IEnumerable<SelectableCategory> SelectedCategories { get; }
Property Value
Remarks
Use this property to retrieve only those categories that have been marked as selected by the user. The returned collection reflects the current selection state and is updated whenever the selection changes. Note that the implementation will query the underlying collection of categories to determine which ones are selected, so it may have performance implications if the collection is large. The Open Trivia database contains a limited number of categories (they change very infrequently) so this is not a concern.
Methods
OnCollectionChanged(NotifyCollectionChangedEventArgs)
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
OnSelectedCategoriesChanged()
Invoked when the collection of selected categories changes to notify listeners of the update.
protected virtual void OnSelectedCategoriesChanged()
Remarks
Override this method in a derived class to implement custom logic that should occur when the SelectedCategories property changes. This method raises the PropertyChanged event for the SelectedCategories property, ensuring that data bindings are updated accordingly.
Events
PropertyChanged
Occurs when a property value changes.
public event PropertyChangedEventHandler? PropertyChanged
Event Type
Remarks
This event is part of the INotifyPropertyChanged interface and is used to notify clients, typically binding clients, that a property value has changed. It is included here in order to allow consumers to subscribe to the event without having to cast the collection to INotifyPropertyChanged.