Class GameViewModel
- Namespace
- Tudormobile.OpenTrivia.UI.ViewModels
- Assembly
- Tudormobile.OpenTrivia.UI.dll
Represents the view model for managing quiz categories and questions, supporting selection of a single question at a time.
public class GameViewModel : ObservableObject, INotifyPropertyChanged, INotifyPropertyChanging
- Inheritance
-
GameViewModel
- Implements
- Inherited Members
Remarks
This view model exposes collections of selectable categories and questions, and ensures that only one question can be selected at any given time. Property change notifications are raised when the selected question changes, enabling data binding scenarios in UI frameworks.
Constructors
GameViewModel(TriviaGame)
Initializes a new instance of the GameViewModel class using the questions provided by the specified TriviaGame.
public GameViewModel(TriviaGame game)
Parameters
gameTriviaGameThe TriviaGame instance containing the collection of questions to be used in the GameViewModel. Cannot be null.
GameViewModel(QuestionCollection)
Initializes a new instance of the GameViewModel class using the specified collection of questions.
public GameViewModel(QuestionCollection questions)
Parameters
questionsQuestionCollectionThe collection of questions to associate with the view model. Cannot be null.
Remarks
The constructor subscribes to the PropertyChanged event of each question in the collection to monitor property updates. The provided questions are also used to populate the categories and are ordered by their question number.
Properties
Categories
Gets the collection of categories that can be selected by the user.
public IReadOnlyList<SelectableCategory> Categories { get; }
Property Value
Remarks
Use this property to access the available categories for selection. The collection is read-only and each category represents a distinct grouping that can be used for organizing or filtering items.
Questions
Gets the collection of questions that can be selected by the user.
public IReadOnlyList<SelectableQuestion> Questions { get; }
Property Value
Remarks
The returned collection is read-only and reflects the set of selectable questions available in the current application context. The contents of the collection may change depending on the application's state.
ResetGameCommand
Gets an IRelayCommand instance wrapping Tudormobile.OpenTrivia.UI.ViewModels.GameViewModel.ResetGame.
[ExcludeFromCodeCoverage]
public IRelayCommand ResetGameCommand { get; }
Property Value
Score
[ObservableProperty]
[ExcludeFromCodeCoverage]
public int Score { get; }
Property Value
SelectedQuestion
Gets or sets the currently selected question in the user interface.
public SelectableQuestion? SelectedQuestion { get; }
Property Value
Remarks
The selected question can be used to display additional details or perform actions related to that question. This property may be null if no question is selected.