Ajout de OnPropertyChanged et de l'interface INotifyPropertyChanged pour implémenter l'évenement de changement et d'actualisation

pull/96/head
Rémi LAVERGNE 11 months ago
parent c875061d18
commit 3d3677ea7f
No known key found for this signature in database
GPG Key ID: 7BCBAE9031E39160

@ -1,3 +1,5 @@
using System.ComponentModel;
namespace Models.Game
{
/// <summary>
@ -5,10 +7,20 @@ namespace Models.Game
/// </summary>
public class OperationCell : Position
{
private bool isChecked;
/// <summary>
/// It tells if the operation is checked or not in the operation grid of the game.
/// </summary>
public bool IsChecked { get; private set; }
public bool IsChecked
{
get => isChecked;
private set
{
isChecked = value;
OnPropertyChanged(nameof(IsChecked));
}
}
/// <summary>
/// Constructor of the OperationCell class.

@ -1,10 +1,13 @@
namespace Models.Game
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Models.Game
{
/// <summary>
/// The Position (x,y) of a cell in the game.
/// </summary>
public class Position
public class Position : INotifyPropertyChanged
{
/// <summary>
/// The X coordinate.
@ -26,5 +29,19 @@
X = x;
Y = y;
}
/// <summary>
/// Event raised when a property is changed to notify the view.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Trigger the PropertyChanged event for a specific property.
/// </summary>
/// <param name="propertyName">Name of the property that changed.</param>
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Loading…
Cancel
Save