public static async Task <Uri> GetAudioRecordingUri(DictionaryEntryViewModel dictionaryEntryViewModel, bool word2)
        {
            DirectionViewModel selectedDirection = dictionaryEntryViewModel.SearchContext.SelectedDirection;

            string word = selectedDirection.ReverseSearch ^ word2 ?
                          dictionaryEntryViewModel.DictionaryEntry.Word2 : dictionaryEntryViewModel.DictionaryEntry.Word1;

            string otherWord = !selectedDirection.ReverseSearch ^ word2 ?
                               dictionaryEntryViewModel.DictionaryEntry.Word2 : dictionaryEntryViewModel.DictionaryEntry.Word1;

            string originLanguageCode      = word2 ? selectedDirection.DestinationLanguageCode : selectedDirection.OriginLanguageCode;
            string destinationLanguageCode = word2 ? selectedDirection.OriginLanguageCode : selectedDirection.DestinationLanguageCode;

            if (urlCache.TryGetValue(new LanguageWordPair(originLanguageCode, word), out Uri audioUri))
            {
                return(audioUri);
            }

            Uri requestUri = GetSearchPageUri(originLanguageCode, destinationLanguageCode, word);

            string response = await httpClient.GetStringAsync(requestUri);

            DictCCSearchResult[] dictCCSearchResults = ExtractDictCCSearchResults(response, originLanguageCode, destinationLanguageCode);

            string wordJSLiteral      = GetJSLiteralOfWord(word);
            string otherWordJSLiteral = GetJSLiteralOfWord(otherWord);

            DictCCSearchResult dictCCSearchResult = null;

            if (wordJSLiteral != string.Empty || otherWordJSLiteral != string.Empty)
            {
                dictCCSearchResult = dictCCSearchResults.FirstOrDefault(result => result.Word1 == wordJSLiteral && result.Word2 == otherWordJSLiteral);
            }

            if (dictCCSearchResult != null)
            {
                audioUri = GetAudioRecordingUri(dictCCSearchResult.ID, originLanguageCode, destinationLanguageCode, originLanguageCode);
            }
            else
            {
                audioUri = null;
            }

            urlCache.Add(new LanguageWordPair(originLanguageCode, word), audioUri);

            return(audioUri);
        }
        private void ListView_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
        {
            void SetRichTextBlockContent(RichTextBlock richTextBlock, Block word)
            {
                if (richTextBlock.Blocks.Count == 0)
                {
                    richTextBlock.Blocks.Add(word);
                }
                else
                {
                    if (richTextBlock.Blocks[0] == word)
                    {
                        // clearing Blocks helps working around a bug with RichTextBlock when reusing Block elements
                        richTextBlock.Blocks.Clear();
                        return;
                    }

                    richTextBlock.Blocks[0] = word;
                }
            }

            DictionaryEntryViewModel viewModel = (DictionaryEntryViewModel)args.Item;

            Grid          templateRoot       = (Grid)args.ItemContainer.ContentTemplateRoot;
            Grid          grid               = (Grid)templateRoot.Children[2];
            RichTextBlock word1RichTextBlock = (RichTextBlock)grid.Children[0];
            RichTextBlock word2RichTextBlock = (RichTextBlock)templateRoot.Children[3];

            SetRichTextBlockContent(word1RichTextBlock, viewModel.Word1);
            SetRichTextBlockContent(word2RichTextBlock, viewModel.Word2);

            Border border = (Border)templateRoot.Children[0];

            if (args.ItemIndex % 2 == 0)
            {
                border.ClearValue(Border.BackgroundProperty);
            }
            else
            {
                border.Background = altBackgroundThemeBrush;
            }
        }