예제 #1
0
        //=====================================================================

        /// <summary>
        /// Constructor
        /// </summary>
        public TopicPreviewerControl()
        {
            if (MamlToFlowDocumentConverter.CodeColorizer == null)
            {
                try
                {
                    string colorizerPath = Path.Combine(ComponentUtilities.ToolsFolder,
                                                        @"PresentationStyles\Colorizer");

                    MamlToFlowDocumentConverter.CodeColorizer = new CodeColorizer(Path.Combine(colorizerPath,
                                                                                               "highlight.xml"), Path.Combine(colorizerPath, "highlight_flowDoc.xsl"))
                    {
                        OutputFormat = OutputFormat.FlowDocument
                    };

                    MamlToFlowDocumentConverter.ColorizerFlowDocumentTemplate = Path.Combine(colorizerPath,
                                                                                             "DocumentTemplate.xaml");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to create code block colorizer.  Reason: " + ex.Message,
                                    Constants.AppName, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }

            converter = new MamlToFlowDocumentConverter();

            browserHistory  = new List <Uri>();
            historyLocation = -1;

            // Merge the shared resources
            this.Resources.MergedDictionaries.Add(SharedResources.SplitButtonStyleResources);

            InitializeComponent();
        }
예제 #2
0
        /// <summary>
        /// This is used to locate a topic by ID and display it
        /// </summary>
        /// <param name="link">The link to the topic</param>
        /// <returns>True if found and displayed, false if not</returns>
        private bool NavigateToTopic(Uri link)
        {
            bool wasFound = false;

            // If there's a topic ID, try to find it
            if (!String.IsNullOrEmpty(link.Host))
            {
                var topics = tableOfContents.Find(
                    t => t.Id.Equals(link.Host, StringComparison.OrdinalIgnoreCase), true);

                if (topics.Any())
                {
                    var topic = topics.First();

                    // If already selected, force it to reload to reflect changes made to the topic
                    if (topic.IsSelected)
                    {
                        tvContent_SelectedItemChanged(this, new RoutedPropertyChangedEventArgs <object>(null, null));
                    }
                    else
                    {
                        topic.IsSelected = true;
                    }

                    wasFound = true;
                }
            }

            // If there's a fragment, try to find the named element and bring it into view
            if (!String.IsNullOrEmpty(link.Fragment) && link.Fragment.Length > 1)
            {
                var element = fdViewer.Document.FindByName(MamlToFlowDocumentConverter.ToElementName(
                                                               link.Fragment.Substring(1))).FirstOrDefault();

                if (element != null)
                {
                    element.BringIntoView();
                    wasFound = true;
                }
                else
                {
                    wasFound = false;
                }
            }

            return(wasFound);
        }
예제 #3
0
        /// <summary>
        /// This is used to locate a topic by ID and display it
        /// </summary>
        /// <param name="link">The link to the topic</param>
        /// <returns>True if found and displayed, false if not</returns>
        private bool NavigateToTopic(Uri link)
        {
            bool wasFound = false;

            // If there's a topic ID, try to find it
            if (!String.IsNullOrEmpty(link.Host))
            {
                var topics = tableOfContents.Find(
                    t => t.Id.Equals(link.Host, StringComparison.OrdinalIgnoreCase), true);

                if (topics.Any())
                {
                    var topic = topics.First();

                    // If already selected, force it to reload to reflect changes made to the topic
                    if (topic.IsSelected)
                    {
                        tvContent_SelectedItemChanged(this, new RoutedPropertyChangedEventArgs <object>(null, null));
                    }
                    else
                    {
                        topic.IsSelected = true;

                        // We need to force the SelectedItemChanged event to run so that the document instance is
                        // updated before we get to the fragment check below.  Haven't found a better way to do
                        // this but it works.
                        if (Application.Current != null && Application.Current.Dispatcher != null)
                        {
                            Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                                  new ThreadStart(delegate { }));
                        }
                    }

                    wasFound = true;
                }
            }

            // If there's a fragment, try to find the named element and bring it into view
            if (!String.IsNullOrEmpty(link.Fragment) && link.Fragment.Length > 1)
            {
                var element = fdViewer.Document.FindByName(MamlToFlowDocumentConverter.ToElementName(
                                                               link.Fragment.Substring(1))).FirstOrDefault();

                if (element != null)
                {
                    // Scroll the element into view.  BringIntoView() doesn't work on the flow document element
                    // so we need to find the scroll viewer that contains it and scroll that instead.
                    DependencyObject child = fdViewer;

                    if (VisualTreeHelper.GetChildrenCount(child) != 0)
                    {
                        while (!(child is ScrollViewer))
                        {
                            child = VisualTreeHelper.GetChild(child as Visual, 0);
                        }

                        ((ScrollViewer)child).ScrollToVerticalOffset(element.ContentStart.GetCharacterRect(
                                                                         LogicalDirection.Forward).Top);
                    }

                    wasFound = true;
                }
                else
                {
                    wasFound = false;
                }
            }

            return(wasFound);
        }