using CoreLibrary.Core; using CoreLibrary.Exceptions; using MauiSpark.Convertisseurs; using System.Globalization; namespace MauiSpark.Vues; public partial class JetonVue : ContentView { public static readonly BindableProperty CouleurProperty = BindableProperty.Create(nameof(Couleur), typeof(Color), typeof(JetonVue), default(Color)); public static readonly BindableProperty CodeProperty = BindableProperty.Create(nameof(Code), typeof(Code), typeof(JetonVue), null); public Color Couleur { get => (Color)GetValue(CouleurProperty); set => SetValue(CouleurProperty, value); } public Code? Code { get => (Code?)GetValue(CodeProperty); set => SetValue(CodeProperty, value); } public JetonVue() { InitializeComponent(); BindingContext = this; } private void QuandTailleChangee(object sender, EventArgs e) { double taille = Math.Min(Grid.Width, Grid.Height) / 2; Cercle.WidthRequest = Cercle.HeightRequest = taille; } private void JetonPresse(object sender, EventArgs e) { if (Cercle == null || !sender.Equals(Cercle) || Code == null || Application.Current == null || Application.Current.MainPage == null) return; Couleur couleur = (Couleur)new CouleurVersCouleurMAUI().ConvertBack(((SolidColorBrush)Cercle.Fill).Color, typeof(Couleur), null, CultureInfo.InvariantCulture); try { Code.AjouterJeton(new Jeton(couleur)); } catch (CodeCompletException) { Application.Current.MainPage.DisplayAlert("Attention", "La code est plein", "OK"); } } }