From 3d3677ea7ff05064eed5364ce1209aba49d75101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Sun, 2 Jun 2024 23:24:23 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Ajout=20de=20OnPropertyChanged=20et?= =?UTF-8?q?=20de=20l'interface=20INotifyPropertyChanged=20pour=20impl?= =?UTF-8?q?=C3=A9menter=20l'=C3=A9venement=20de=20changement=20et=20d'actu?= =?UTF-8?q?alisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/Trek-12/Models/Game/OperationCell.cs | 14 +++++++++++++- source/Trek-12/Models/Game/Position.cs | 21 +++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/source/Trek-12/Models/Game/OperationCell.cs b/source/Trek-12/Models/Game/OperationCell.cs index d8ac6da..c17791d 100644 --- a/source/Trek-12/Models/Game/OperationCell.cs +++ b/source/Trek-12/Models/Game/OperationCell.cs @@ -1,3 +1,5 @@ +using System.ComponentModel; + namespace Models.Game { /// @@ -5,10 +7,20 @@ namespace Models.Game /// public class OperationCell : Position { + + private bool isChecked; /// /// It tells if the operation is checked or not in the operation grid of the game. /// - public bool IsChecked { get; private set; } + public bool IsChecked + { + get => isChecked; + private set + { + isChecked = value; + OnPropertyChanged(nameof(IsChecked)); + } + } /// /// Constructor of the OperationCell class. diff --git a/source/Trek-12/Models/Game/Position.cs b/source/Trek-12/Models/Game/Position.cs index c1b75da..d34ece5 100644 --- a/source/Trek-12/Models/Game/Position.cs +++ b/source/Trek-12/Models/Game/Position.cs @@ -1,10 +1,13 @@ -namespace Models.Game +using System.ComponentModel; +using System.Runtime.CompilerServices; + +namespace Models.Game { /// /// The Position (x,y) of a cell in the game. /// - public class Position + public class Position : INotifyPropertyChanged { /// /// The X coordinate. @@ -26,5 +29,19 @@ X = x; Y = y; } + + /// + /// Event raised when a property is changed to notify the view. + /// + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Trigger the PropertyChanged event for a specific property. + /// + /// Name of the property that changed. + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } } \ No newline at end of file