private void ValidCaRButton_OnClick(object sender, RoutedEventArgs e) { //controle des données var ok = true; if (string.IsNullOrWhiteSpace(TitreCaRTextBox.Text)) { TitreCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 150, 0, 0)); ok = false; } else { TitreCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); } var heure = 0; var minutes = 0; var secondes = 0; if (!string.IsNullOrWhiteSpace(HeureCaRTextBox.Text) && !int.TryParse(HeureCaRTextBox.Text, out heure) || heure < 0) { HeureCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 150, 0, 0)); ok = false; } else { HeureCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); } if (!string.IsNullOrWhiteSpace(MinuteCaRTextBox.Text) && (!int.TryParse(MinuteCaRTextBox.Text, out minutes) || (int.TryParse(MinuteCaRTextBox.Text, out minutes) && (minutes > 59 || minutes < 0)))) { MinuteCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 150, 0, 0)); ok = false; } else { MinuteCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); } if (!String.IsNullOrWhiteSpace(SecondeCaRTextBox.Text) && (!int.TryParse(SecondeCaRTextBox.Text, out secondes) || (int.TryParse(SecondeCaRTextBox.Text, out secondes) && (secondes > 59 || secondes < 0)))) { SecondeCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 150, 0, 0)); ok = false; } else { SecondeCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); } if (String.IsNullOrWhiteSpace(SecondeCaRTextBox.Text) && String.IsNullOrWhiteSpace(MinuteCaRTextBox.Text) && String.IsNullOrWhiteSpace(HeureCaRTextBox.Text)) { SecondeCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 150, 0, 0)); MinuteCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 150, 0, 0)); HeureCaRTextBox.Background = new SolidColorBrush(Color.FromArgb(255, 150, 0, 0)); } //si tout est ok on créer le timer et on l'envoi à MainPage pour l'envoi à ViewModel if (!ok) { return; } var nbSec = DateUtils.ConvertirHeureSecondes(heure, minutes, secondes); var car = new CaR { Titre = TitreCaRTextBox.Text, NbSecondes = nbSec, TempsDefaut = nbSec }; //si c'est une modif, ont remet l'ID if (_idTimerModif > 0) { car.Id = _idTimerModif; } _ajoutTimer(car); //retour à MainPage if (Frame.CanGoBack) { Frame.GoBack(); } }