Пример #1
0
        /// <summary>
        /// Command callback.
        /// Navigates back in the navigation history.
        /// </summary>
        private void OnNavigateBack()
        {
            try
            {
                KanjiNavigationEntry entry = _navigationHistory.Pop();
                RaisePropertyChanged("CanNavigateBack");

                // Apply the filter.
                _kanjiFilter = entry.KanjiFilter;
                KanjiFilterVm.SetFilter(_kanjiFilter);
                if (_kanjiDetailsVm != null)
                {
                    KanjiListVm.Navigate(_kanjiFilter,
                                         _kanjiDetailsVm.KanjiEntity.DbKanji);
                }
                else
                {
                    KanjiListVm.SetFilter(_kanjiFilter);
                }

                // Reset the kanji details viewmodel.
                SetKanjiDetailsVm(entry.KanjiDetailsVm);
            }
            catch (InvalidOperationException)
            {
                // The command was fired several times in a
                // row and the navigation history was empty.
                //
                // No problem, just ignore the exception.
            }
        }
Пример #2
0
        /// <summary>
        /// Navigates to the kanji referred by the given character.
        /// Filters using the referred vocab kanji writing string.
        /// Writes a navigation history entry to trace back to the
        /// navigation state active before the operation.
        /// </summary>
        /// <param name="character">
        /// Character driving the navigation.</param>
        public void Navigate(KanjiWritingCharacter character)
        {
            if (KanjiDetailsVm != null)
            {
                // Temporarily unsubscribe the event.
                KanjiDetailsVm.KanjiNavigated -= OnKanjiNavigated;
            }

            // Add the current state to the navigation history.
            PushNavigationHistoryEntry();

            // Create a new filter matching the vocab word selected.
            _kanjiFilter = new KanjiFilter()
            {
                TextFilter = character.OriginalVocab.KanjiWriting,
                // Ignore the levels because not only are they irrelevant,
                // they might not even be the same for the kanji as for the vocab.
                JlptLevel = Levels.IgnoreJlptLevel,
                WkLevel   = Levels.IgnoreWkLevel
            };

            // Apply the filter
            KanjiFilterVm.SetFilter(_kanjiFilter);
            KanjiListVm.Navigate(_kanjiFilter, character.Kanji);

            // Create a new KanjiDetailsVm.
            // Do not use the SetKanjiDetailsVm method as to not dispose
            // the previous value.
            KanjiDetailsVm = new KanjiDetailsViewModel(new ExtendedKanji(character.Kanji));

            // Re-subscribe the event.
            KanjiDetailsVm.KanjiNavigated += OnKanjiNavigated;
        }