// update GUI private void UpdateInserted(bool wasPayed = false) { InsertedAmount.Content = ((float)insertedMoney.Sum() / 100).ToString("C2"); if (transaction.GetCostInCent() <= insertedMoney.Sum() && !wasPayed) { PayButton.IsEnabled = true; PayButton.ClearValue(BackgroundProperty); } else { PayButton.IsEnabled = false; PayButton.Background = Brushes.LightGray; } }
// on click of coin button private void OnMoneyButton_Click(object sender, RoutedEventArgs eventArgs, int valueInCent) { insertedMoney.Add(valueInCent); Button button = new Button() { Content = ((float)valueInCent / 100).ToString("C2"), Background = Brushes.LightGreen, Foreground = Brushes.Black, Margin = new Thickness(3) }; button.Click += (s, e) => { InsertedPanel.Children.Remove((Button)s); insertedMoney.Remove(valueInCent); UpdateInserted(); }; InsertedPanel.Children.Add(button); if (transaction.GetCostInCent() <= insertedMoney.Sum()) { PayButton.IsEnabled = true; PayButton.ClearValue(BackgroundProperty); } UpdateInserted(); }