WPF finds Hyperlink, wpfflowdocument from FlowDocument

Source: Internet
Author: User

[Go] WPF finds Hyperlink, wpfflowdocument from FlowDocument

Original article address: How can I get a FlowDocument Hyperlink to launch browser and go to URL in a WPF app?

 #region Activate Hyperlinks in the Rich Text box        //http://stackoverflow.com/questions/5465667/handle-all-hyperlinks-mouseenter-event-in-a-loaded-loose-flowdocument        void SubscribeToAllHyperlinks(FlowDocument flowDocument)        {            var hyperlinks = GetVisuals(flowDocument).OfType<Hyperlink>();            foreach (var link in hyperlinks)                link.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(link_RequestNavigate);        }        public static IEnumerable<DependencyObject> GetVisuals(DependencyObject root)        {            foreach (var child in LogicalTreeHelper.GetChildren(root).OfType<DependencyObject>())            {                yield return child;                foreach (var descendants in GetVisuals(child))                    yield return descendants;            }        }        void link_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)        {            //http://stackoverflow.com/questions/2288999/how-can-i-get-a-flowdocument-hyperlink-to-launch-browser-and-go-to-url-in-a-wpf            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));            e.Handled = true;        }        #endregion Activate Hyperlinks in the Rich Text box

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.