コード例 #1
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                Dictionary<String, Object> p = e.Parameter as Dictionary<String, Object>;
                if (p.ContainsKey("Deck"))
                {
                    this.currentDeck = p["Deck"] as Deck;
                    this.DataContext = this.currentDeck;
                    if (p.ContainsKey("Card"))
                    {
                        this.currentCard = p["Card"] as Card;
                    }
                    else
                    {
                        this.currentCard = new Card();
                        this.isNewCard = true;
                    }
                    SideAStackPanel.DataContext = this.currentCard;
                    SideBStackPanel.DataContext = this.currentCard;
                    if (this.currentCard.hasSideAImage()) {
                        ClearSideAImgBtn.IsEnabled = true;
                    }
                    if (this.currentCard.hasSideBImage())
                    {
                        ClearSideBImgBtn.IsEnabled = true;
                    }
                }
                else
                {
                    ShowErrorAndGoBack("The current deck is invalid");
                }

            }
            else
            {
                ShowErrorAndGoBack("The current deck is invalid");
            }

        }
コード例 #2
0
        public bool processXml()
        {
            //Process this.deckXml and:
            //Populate Deck [title, sideA and sideB names, description]
            //Populate Cards, linking to bitmaps that are loaded in localstorage.
            //return true if succeeded
            using (XmlReader reader = XmlReader.Create(new StringReader(this.deckXml)))
            {
                Card currentCard = null;
                int tabDepth = 0;
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            if ((tabDepth == 0))
                            {
                                if (reader.Name.Equals("deck"))
                                {
                                    tabDepth++;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                            else
                            {
                                tabDepth++;
                                if (reader.Name.Equals("title"))
                                {
                                    this.deck.setTitle(System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString()));
                                    Debug.WriteLine("Set deck title to " + this.deck.getTitle());
                                }
                                else if (reader.Name.Equals("description"))
                                {
                                    //SET DESCRIPTION!
                                    Debug.WriteLine("Deck Description: " + System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString()));
                                }
                                else if (reader.Name.Equals("sideaname"))
                                {
                                    this.deck.setSideAName(System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString()));
                                }
                                else if (reader.Name.Equals("sidebname"))
                                {
                                    this.deck.setSideBName(System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString()));
                                }
                                else if (reader.Name.Equals("cards"))
                                {
                                    tabDepth++;
                                }
                                else if (reader.Name.Equals("card"))
                                {
                                    tabDepth++;
                                    currentCard = new Card();
                                }
                                else if (reader.Name.Equals("sidealabel"))
                                {
                                    currentCard.sideALabel = System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString());
                                }
                                else if (reader.Name.Equals("sideblabel"))
                                {
                                    currentCard.sideBLabel = System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString());
                                }
                                else if (reader.Name.Equals("sideaimage"))
                                {
                                    currentCard.setSideAImage("ms-appdata:///temp/" + System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString()));
                                }
                                else if (reader.Name.Equals("sidebimage"))
                                {
                                    currentCard.setSideBImage("ms-appdata:///temp/" + System.Net.WebUtility.HtmlDecode(reader.ReadElementContentAsString()));
                                }

                            }
                            break;
                        case XmlNodeType.Comment:
                            break;
                        case XmlNodeType.Text:
                            break;
                        case XmlNodeType.XmlDeclaration:
                            break;
                        case XmlNodeType.EndElement:
                            if (reader.Name.Equals("card") || reader.Name.Equals("cards") || reader.Name.Equals("deck"))
                            {
                                tabDepth--;
                            }
                            if (reader.Name.Equals("card"))
                            {
                                //Card info is ready, add to deck!
                                this.deck.addCard(currentCard);
                            }
                            break;
                    }
                }

                Debug.WriteLine("Deck '" + this.deck.getTitle() + "' has " + this.deck.getLength() + " cards.");
            }
            return true;
        }
コード例 #3
0
ファイル: Deck.cs プロジェクト: ryansloan/QuizCards
 public bool addCard(Card c)
 {
     this.cards.Add(c);
     return true;
 }