public void SetParameters(List<Word> wordList, WordSource wordSource, int wordCardType, int startIndex)
 {
     this.wordList = wordList;
     this.wordSource = wordSource;
     this.wordCardType = wordCardType;
     this.startIndex = startIndex;
 }
        public WordCardLearning()
        {
            InitializeComponent();
            BuildApplicationBar();

            isNewPageInstance = true;
            currentWordIndex = 0;
            startTime = new DateTime();

            // set parameters default value
            wordList = null;
            wordSource = null;
            wordCardType = 0;
            startIndex = 0;
        }
        public DictationPage()
        {
            InitializeComponent();
            //isNewPageInstance = true;
            currentWordIndex = 0;
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            waittimer = new DispatcherTimer();
            waittimer.Interval = TimeSpan.FromSeconds(1);


            wordList = null;
            wordSource = null;
            wordCardType = 0;
            startIndex = 0;
            waittime = 0;
            currentword = new Word();
            currentCount = 0;
        }
        private void RestorePageStates()
        {
            if (State.ContainsKey(PageStateStrings.WORD_LIST))
            {
                wordList = State[PageStateStrings.WORD_LIST] as List<Word>;
                TextBlock_WordCount.Text = wordList.Count.ToString();
                ProgressBar_Progress.Maximum = wordList.Count;
            }
            if (State.ContainsKey(PageStateStrings.WORD_SOURCE_ID))
            {
                int sourceId = int.Parse(State[PageStateStrings.WORD_SOURCE_ID] as string);
                List<WordSource> wordSourceList = (Application.Current as App).wordSourceList;
                wordSource = WordSourceHelper.GetWordSourceById(wordSourceList , sourceId);
                TextBlock_Title.Text = wordSource.title;
            }
            if (State.ContainsKey(PageStateStrings.WORD_CARD_TYPE))
            {
                wordCardType = int.Parse(State[PageStateStrings.WORD_CARD_TYPE] as string);
            }
            if (State.ContainsKey(PageStateStrings.CURRENT_WORD_INDEX))
            {
                currentWordIndex = int.Parse(State[PageStateStrings.CURRENT_WORD_INDEX] as string);
                TextBlock_CurrentWordNumber.Text = (currentWordIndex + 1).ToString();
                ProgressBar_Progress.Value = currentWordIndex + 1;
            }

            if (State.ContainsKey(PageStateStrings.WORD_LIST) && State.ContainsKey(PageStateStrings.WORD_CARD_TYPE) && State.ContainsKey(PageStateStrings.CURRENT_WORD_INDEX))
            {
                UserControl_WordCardCanvas.SetParameter(wordList, wordCardType, currentWordIndex);
                UpdateUI();
            }
        }
        public static bool ReadRunState(List<WordSource> wordSourceList, out List<Word> wordList, out WordSource wordSource, out int cardType, out int startIndex)
        {
            wordList = null;
            wordSource = null;
            cardType = 0;
            startIndex = 0;

            using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (file.FileExists("LastRun"))
                {
                    using (IsolatedStorageFileStream fileStream = file.OpenFile("LastRun", FileMode.Open, FileAccess.Read))
                    {
                        RunState rs = new DataContractSerializer(typeof(RunState)).ReadObject(fileStream) as RunState;
                        int sourceId = rs.sourceId;
                        wordSource = WordSourceHelper.GetWordSourceById(wordSourceList, sourceId);
                        if (wordSource == null)
                        {
                            DeleteRunState();
                            return false;
                        }
                        else
                        {
                            wordList = rs.wordList;
                            cardType = rs.cardType;
                            startIndex = rs.startIndex;
                            return true;
                        }
                    }
                }
                else return false;
            }
        }
        private void SelectedWordList()
        {
            selectedWordSource = ListPicker_WordSource.SelectedItem as WordSource;
            wordSourceUri = selectedWordSource.fileUri;
            wordList = WordFileHelper.ReadWordFileToList(wordSourceUri);
            wordCardType = ListPicker_CardType.SelectedIndex + 1;

            // filter words
            if (ListPicker_WordType.SelectedIndex == 1) // noun only
            {
                List<Word> NoneWordList = new List<Word>();
                for (int i = 0; i < wordList.Count; i++)
                {
                    if (wordList[i] is Noun)
                        NoneWordList.Add(wordList[i]);
                }
                if (ListPicker_Gender.SelectedIndex == 0)
                {

                    wordList = NoneWordList;
                }
                else
                {
                    if (ListPicker_Gender.SelectedIndex == 1)
                    {
                        List<Word> updatedWordList = new List<Word>();
                        foreach (Noun temp in NoneWordList)
                        {
                            if (temp.gender == WordGender.Masculine)
                            {
                                updatedWordList.Add(temp);
                            }
                        }
                        wordList = updatedWordList;
                    }
                    else if (ListPicker_Gender.SelectedIndex == 2)
                    {
                        List<Word> updatedWordList = new List<Word>();
                        foreach (Noun temp in NoneWordList)
                        {
                            if (temp.gender == WordGender.Feminine)
                            {
                                updatedWordList.Add(temp);
                            }
                        }
                        wordList = updatedWordList;
                    }
                    else if (ListPicker_Gender.SelectedIndex == 3)
                    {
                        List<Word> updatedWordList = new List<Word>();
                        foreach (Noun temp in NoneWordList)
                        {
                            if (temp.gender == WordGender.Neuter)
                            {
                                updatedWordList.Add(temp);
                            }
                        }
                        wordList = updatedWordList;
                    }
                    else if (ListPicker_Gender.SelectedIndex == 4)
                    {
                        List<Word> updatedWordList = new List<Word>();
                        foreach (Noun temp in NoneWordList)
                        {
                            if (temp.gender == WordGender.MasculineOrNeuter)
                            {
                                updatedWordList.Add(temp);
                            }
                        }
                        wordList = updatedWordList;
                    }
                }


            }
            else if (ListPicker_WordType.SelectedIndex == 2) // verb only
            {
                List<Word> updatedWordList = new List<Word>();
                for (int i = 0; i < wordList.Count; i++)
                {
                    if (wordList[i] is Verb)
                        updatedWordList.Add(wordList[i]);
                }
                wordList = updatedWordList;
            }
            else if (ListPicker_WordType.SelectedIndex == 3) // phrase only
            {
                List<Word> updatedWordList = new List<Word>();
                for (int i = 0; i < wordList.Count; i++)
                {
                    if (wordList[i].wordType == WordType.Phrase)
                        updatedWordList.Add(wordList[i]);
                }
                wordList = updatedWordList;
            }

            if (ListPicker_AppearanceOrder.SelectedIndex == 1)  // random
            {
                List<Word> updatedWordList = new List<Word>();
                int wordListCount = wordList.Count;
                for (int i = 0; i < wordListCount; i++)
                {
                    Random random = new Random();
                    int selectedIndex = random.Next(wordList.Count);
                    updatedWordList.Add(wordList[selectedIndex]);
                    wordList.RemoveAt(selectedIndex);
                }
                wordList = updatedWordList;
            }
            if (wordList.Count == 0)
            {
                canNav = false;
                MessageBox.Show("此范围无卡片");
            }
            else
            {
                canNav = true;
            }
        }