public void SetFlashCard(UIViewAnimationTransition transition) { if (currentFlashCard < 0) { currentFlashCard = FlashCards.Count - 1; } else if (currentFlashCard >= FlashCards.Count) { currentFlashCard = 0; } FlashCard newFlashCard = FlashCards[currentFlashCard]; if (FlashCardView != null && newFlashCard == FlashCardView.Flashcard) { return; } UIView.BeginAnimations("swipe"); UIView.SetAnimationDuration(1.25); UIView.SetAnimationCurve(UIViewAnimationCurve.EaseInOut); UIView.SetAnimationTransition(transition, this.View, false); FlashCardView.RemoveFromSuperview(); FlashCardView = new FlashCardView(newFlashCard); this.View.AddSubview(FlashCardView); UIView.CommitAnimations(); }
public FlashCardView(FlashCard flashcard) { backgroundView = new UIView(){BackgroundColor = UIColor.Black}; this.BackgroundColor = UIColor.Black; Flashcard = flashcard; Word = new UILabel (){Text = Flashcard.Word,AdjustsFontSizeToFitWidth = true,BackgroundColor = UIColor.White,Font = UIFont.BoldSystemFontOfSize(200),TextAlignment = UITextAlignment.Center}; Image = new UIImageView (new UIImage (Flashcard.Image)); this.AddSubview(backgroundView); backgroundView.AddSubview (Word); this.AddGestureRecognizer(new UITapGestureRecognizer(Tapped)); }
private void btnNext_Click(object sender, RoutedEventArgs e) { // Get the index for the next card we need ++_currentIndex; // Enable the back button if we're at the 2nd or later card if (_currentIndex > 0) { btnPrev.IsEnabled = true; } FlashCard card = null; // If there's currently no card to show or we've reached the end // of all the cards we've already shown, pluck one from _flashCards if (_shownFlashCards.Count == 0 || _currentIndex >= _shownFlashCards.Count) { int randomIndex = _random.Next(0, _flashCards.Count); card = _flashCards[randomIndex]; // Add it to the list of cards made visible _shownFlashCards.Add(card); // Remove it from the list of possible new cards to show _flashCards.Remove(card); } else { // Otherwise we show the next card in the queue of cards we've shown card = _shownFlashCards[_currentIndex]; } if (card != null) { lblQuestion.Content = card.Question; expAnswer.IsExpanded = false; lblAnswer.Content = card.Answer; } // If there's not another card we can show and no new cards to choose // then we disable the next button if (_currentIndex >= _shownFlashCards.Count - 1 && _flashCards.Count == 0) { btnNext.IsEnabled = false; } }
public FlashCardView(FlashCard flashcard) { backgroundView = new UIView() { BackgroundColor = UIColor.Black }; this.BackgroundColor = UIColor.Black; Flashcard = flashcard; Word = new UILabel() { Text = Flashcard.Word, AdjustsFontSizeToFitWidth = true, BackgroundColor = UIColor.White, Font = UIFont.BoldSystemFontOfSize(200), TextAlignment = UITextAlignment.Center }; Image = new UIImageView(new UIImage(Flashcard.Image)); this.AddSubview(backgroundView); backgroundView.AddSubview(Word); this.AddGestureRecognizer(new UITapGestureRecognizer(Tapped)); }
private void OpenCmdExecuted(object sender, ExecutedRoutedEventArgs e) { lblQuestion.Content = ""; lblAnswer.Content = ""; expAnswer.IsExpanded = false; OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "XML Files |*.xml"; dlg.RestoreDirectory = true; if (dlg.ShowDialog() == true) { try { XDocument doc = XDocument.Load(dlg.FileName); // Get all the flash cards in the doc var cards = from c in doc.Descendants("FlashCard") select new { Question = c.Element("Question").Value, Answer = c.Element("Answer").Value }; // Create a flash FlashCard object for every flash card // found in the XML file. foreach (var card in cards) { FlashCard fco = new FlashCard(card.Question, card.Answer); _flashCards.Add(fco); } btnNext.IsEnabled = true; btnPrev.IsEnabled = false; } catch (Exception) { _flashCards.Clear(); } } ; }