/// <summary>
        /// Updates the list of search results when the SearchResults property is set.
        /// </summary>
        private void PopulateSearchResults()
        {
            searchResultsListBox.Items.Clear();
            Style listItemStyle = Application.Current.Resources[Strings.ListItemStyleKey] as Style;

            if(SearchResults == null || SearchResults.Count == 0)
            {
                TextBlock noResults = new TextBlock();
                noResults.Text = "No search results found.";
                resultsHeader.Text = "Results:";

                ExtendedListBoxItem newItem = new ExtendedListBoxItem();
                newItem.Content = noResults;
                AutomationProperties.SetHelpText(newItem, "No results found for this search, please go back and try a different search.");
                searchResultsListBox.Items.Add(newItem);
                if(IndicateSearchResultsChanged != null)
                {
                    IndicateSearchResultsChanged(this, new EventArgs());
                }

                SelfVoicingSpeakText(this, new SpeechTextEventArgs(noResults.Text));
                return;
            }

            //Populate the search results box
            foreach(SearchResult result in SearchResults)
            {
                //Construct ListBoxItem from textblock of multiple runs
                ExtendedListBoxItem currentItem = new ExtendedListBoxItem();
                currentItem.Style = listItemStyle;
                currentItem.SetBinding(ExtendedListBoxItem.SelectionBackgroundProperty, _selectionBackgroundBinding);
                currentItem.SetBinding(ForegroundProperty, _defaultForegroundBinding);

                TextBlock displayedResult = new TextBlock();

                int currentIndex = 0;

                while(currentIndex < result.Text.Length)
                {
                    // get the next occurance of the search string in the search result
                    int nextSearchStringIndex = result.Text.Substring(currentIndex).ToLower().IndexOf(result.SearchString.ToLower());

                    if(nextSearchStringIndex == -1)
                    {
                        break;
                    }

                    // construct a run for the text leading up to the match
                    if(currentIndex != nextSearchStringIndex)
                    {
                        Run preSearchWord = new Run();
                        preSearchWord.Text = result.Text.Substring(currentIndex, nextSearchStringIndex);
                        displayedResult.Inlines.Add(preSearchWord);
                    }

                    //if (nextSearchStringIndex)
                    Run SearchWord = new Run();

                    SearchWord.Text = result.Text.Substring(currentIndex + nextSearchStringIndex, result.SearchString.Length);
                    SearchWord.FontWeight = FontWeights.Bold;
                    displayedResult.Inlines.Add(SearchWord);

                    currentIndex += (nextSearchStringIndex + result.SearchString.Length);
                }

                Run postSearchWord = new Run();

                if(currentIndex != result.Text.Length)
                {
                    postSearchWord.Text = result.Text.Substring(currentIndex);
                    displayedResult.Inlines.Add(postSearchWord);
                }

                displayedResult.TextWrapping = TextWrapping.Wrap;
                currentItem.Content = displayedResult;
                AutomationProperties.SetHelpText(currentItem, result.Text + ". Use the up and down arrow keys to scroll through the other search results.");

                //We don't want to have to tab through all of the search result items, since up and down already do that
                currentItem.TabNavigation = KeyboardNavigationMode.Once;
                currentItem.IsTabStop = false;

                searchResultsListBox.Items.Add(currentItem);
            }

            searchResultsListBox.InvalidateMeasure();
            if(IndicateSearchResultsChanged != null)
            {
                IndicateSearchResultsChanged(this, new EventArgs());
            }

            //TODO: Distinguish plural and singular (i.e. result from results)
            resultsHeader.Text = String.Format("Results: ({0} results found)", SearchResults.Count);

            SelfVoicingSpeakText(this, new SpeechTextEventArgs(string.Format(Speech.ResultsFoundMessage, SearchResults.Count)));
        }
        /// <summary>
        /// Refreshes the items displayed in the Table of Contents. Called when the TOC reference is (re)set.
        /// </summary>
        private void PopulateTableOfContents()
        {
            // empty out the table of contents listbox and render new table of contents
            TableOfContentsListBox.SelectedItem = null;
            TableOfContentsListBox.Items.Clear();

            foreach(Heading heading in _tableOfContents.FlatHeadingList)
            {
                var newItem = new ExtendedListBoxItem();
                if(Application.Current.Resources.Contains(Strings.ListItemStyleKey))
                {
                    newItem.Style = Application.Current.Resources[Strings.ListItemStyleKey] as Style;
                }
                newItem.SetBinding(ExtendedListBoxItem.SelectionBackgroundProperty, _selectionBackgroundBinding);
                newItem.SetBinding(ForegroundProperty, _defaultForegroundBinding);
                newItem.Content = heading.Text;
                // margin for header, set as multiple of level, currently fixed indentation size
                newItem.Margin = new Thickness(heading.level * 15, 0, 0, 0);
                newItem.Padding = new Thickness(0, 0, 0, 0);
                newItem.Height = 20;

                //Set the automation name for each list box item
                AutomationProperties.SetAutomationId(newItem, heading.Text);
                AutomationProperties.SetHelpText(newItem, heading.Text + ". Use the up and down arrow keys to scroll through the other headings in this book.");
                //newItem.GotFocus += SpeakControlOnFocus;

                TableOfContentsListBox.Items.Add(newItem);
            }
            if(IndicateSearchResultsChanged != null)
            {
                IndicateSearchResultsChanged(this, new EventArgs());
            }

            //Reset to first heading.
            SelectedElement = 0;
        }