namespace ShoopNCook.Views; // Classe représentant une vue avec un compteur public partial class CounterView : ContentView { // Propriété liée pour le nombre à afficher private readonly BindableProperty CountProperty = BindableProperty.Create(nameof(CountLabel), typeof(uint), typeof(CounterView), default(uint) + 1); // Propriété liée pour le texte à afficher private readonly BindableProperty CounterLabelProperty = BindableProperty.Create(nameof(CounterLabel), typeof(string), typeof(CounterView), default(string)); public CounterView() { InitializeComponent(); // Liaison des propriétés à leurs étiquettes respectives CountLabel.BindingContext = this; CountLabel.SetBinding(Label.TextProperty, nameof(Count)); CounterLabel.BindingContext = this; CounterLabel.SetBinding(Label.TextProperty, nameof(CounterText)); } // Accesseurs pour Count public uint Count { get => (uint)GetValue(CountProperty); set { // Assure que la valeur est toujours au minimum 1 SetValue(CountProperty, value <= 1 ? 1 : uint.Parse(value.ToString())); OnPropertyChanged(nameof(Count)); } } // Accesseurs pour CounterText public string CounterText { get => (string)GetValue(CounterLabelProperty); set { SetValue(CounterLabelProperty, value); OnPropertyChanged(nameof(CounterText)); } } // Méthodes pour augmenter et diminuer le compteur private void OnPlus(object o, EventArgs e) { Count += 1; } private void OnMinus(object o, EventArgs e) { Count -= 1; } }