You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
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;
|
|
}
|
|
}
|