Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:29:26+00:00 2026-06-13T04:29:26+00:00

I need to bind text which may contain hyperlinks to RichTextBox so it could

  • 0

I need to bind text which may contain hyperlinks to RichTextBox so it could show text as normal text and links as hyperlinks.

For example I have following text:

Join us on social networks
http://www.facebook.com/

I want that links in a text be hyperlinks so the result in RichTextBox would be like this:

Join us on social networks

http://www.facebook.com/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:29:27+00:00Added an answer on June 13, 2026 at 4:29 am

    I implemented what I need

    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Text.RegularExpressions;
    using System.Windows.Media;
    
    namespace NazarGrynko.UI.Controls
    {
        public class MyRichTextBox : RichTextBox
        {
            private const string UrlPattern = @"(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?";
            public static readonly DependencyProperty TextProperty =
                DependencyProperty.Register("Text", typeof (string), typeof(MyRichTextBox ), new PropertyMetadata(default(string), TextPropertyChanged));
    
            public string Text
            {
                get { return (string) GetValue(TextProperty); }
                set { SetValue(TextProperty, value); }
            }
    
            private static void TextPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
            {
                var richTextBox = (MyRichTextBox)dependencyObject;
                var text = (string) dependencyPropertyChangedEventArgs.NewValue;
                int textPosition = 0;
                var paragraph = new Paragraph();
    
                var urlMatches = Regex.Matches(text, UrlPattern);
                foreach (Match urlMatch in urlMatches)
                {
                    int urlOccurrenceIndex = text.IndexOf(urlMatch.Value, textPosition, StringComparison.Ordinal);
    
                    if (urlOccurrenceIndex == 0)
                    {
                        var hyperlink = new Hyperlink
                                            {
                                                NavigateUri = new Uri(urlMatch.Value),
                                                TargetName = "_blank",
                                                Foreground = Application.Current.Resources["PhoneAccentBrush"] as Brush
                                            };
                        hyperlink.Inlines.Add(urlMatch.Value);
                        paragraph.Inlines.Add(hyperlink);
                        textPosition += urlMatch.Value.Length;
                    }
                    else
                    {
                        paragraph.Inlines.Add(text.Substring(textPosition, urlOccurrenceIndex - textPosition));
                        textPosition += urlOccurrenceIndex - textPosition;
                        var hyperlink = new Hyperlink
                                            {
                                                NavigateUri = new Uri(urlMatch.Value),
                                                TargetName = "_blank",
                                                Foreground = Application.Current.Resources["PhoneAccentBrush"] as Brush
                                            };
                        hyperlink.Inlines.Add(urlMatch.Value);
                        paragraph.Inlines.Add(hyperlink);
                        textPosition += urlMatch.Value.Length;
                    }
                }
    
                if (urlMatches.Count == 0)
                {
                    paragraph.Inlines.Add(text);
                }
    
                richTextBox.Blocks.Add(paragraph);
            }
        }
    }
    

    Using example:

    <MyRichTextBox Text="{Binding Message}"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following markup which I need to bind a click event to
I bind keyDown , keyPress and keyUp events to a text input. I need
i need to bind a collection of objects to a combo box which i
I need to bind to a Storyboard, but I cant figure how. I have
I have a situation where I need to bind a click event to an
Me need set item checkbox when i click on element span which have this
I have a query where I need to select text with a colon inside,
I have an input, type text, element which is being validated using MVC3 validation
I have the following view model which contains an array of elements function ReservationsViewModel()
I have a need to bind some HTML to an object, but my issue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.