Clickable Text Input Control Needed...

4 posts, 0 answers
  1. Nikhil Thaker
    Nikhil Thaker avatar
    22 posts
    Member since:
    Mar 2010

    Posted 28 Dec 2010 Link to this post

    Hi,

    I need a input control which checks for input string on each key up event. If the input string found equal to URI(that we can do with REGEX off course) then it converts that string to hyperlink and make it self clickable.
    I think i can probably do that with RadRichTextBox control.. So please let me know how I can do that...?

    thanks in advance....
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 31 Dec 2010 Link to this post

    Hi Nikhil Thaker,

    We are considering adding this feature in the future. A possible approach you can adopt until we provide it, is as shown in the code below:

    private string regEx = @"http://\S*";
     
          private void radRichTextBox1_KeyDown(object sender, KeyEventArgs e)
          {
              if (e.Key == Key.Enter)
              {
                  SearchString(((RadRichTextBox)sender).Document, regEx);
              }
          }
     
          private void SearchString(RadDocument doc, string toSearch)
          {
              DocumentPosition caretPosition = new DocumentPosition(doc.CaretPosition);
              DocumentTextSearch search = new DocumentTextSearch(doc);
              IEnumerable<TextRange> result = search.FindAll(toSearch);
              foreach (TextRange range in result)
              {            
                  MakeHyperlinkFromRange(doc, range);             
              }
              doc.CaretPosition.MoveToPosition(caretPosition);
          }
     
          private void MakeHyperlinkFromRange(RadDocument doc, TextRange range)
          {
              range.SetSelection(doc);
              string selectedText = doc.Selection.GetSelectedText();
              doc.Delete(false);
              Hyperlink link = new Hyperlink(selectedText, selectedText, HyperlinkTargets.Blank);
              doc.InsertInline(link);
          }

    There are a few things worth noting here:
    1. FindAll() accepts a string as a parameter and regards it as pattern of a regular expression. In the example, it selects everything starting with "http://" and ending in a whitespace.
    2. The KeyUp and KeyDown events of RadRichTextBox when pressing Tab are handled, so that it does not pass the focus to the next control on the page, but inserts a tabulation. Thus, you won't be able to substitute the text for a hyperlink on pressing the Tab key.
    3. Making hyperlinks on Key.Space can also be problematic due to the way RadRichTextBox works currently. (If you type a letter and press space within a very short interval of time, the letter will not be included in the hyperlink and the interval will be inserted after the letter.)

    Kind regards,
    Iva
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. Nikhil Thaker
    Nikhil Thaker avatar
    22 posts
    Member since:
    Mar 2010

    Posted 07 Feb 2011 Link to this post

    Hi,
     
    I am getting an exception on adding RadRichTextBox and running the application on InitializeComponents() method of constructor..
    Exception Details  : "The invocation of the constructor on type 'MyControl' that matches the specified binding constraints threw an exception."

    Here is the details where i am using the radrichtextbox..

    RadGridView --> GridViewDataColumn --> Cell Template --> DataTemplate --> Custom UserControl --> RadDropDownButton --> RadDropDownButton.Content --> RadRichTextBox...

    Please help me solve the issue..

    Thanks in Advance..
  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 10 Feb 2011 Link to this post

    Hi Nikhil Thaker,

    I couldn't reproduce the error you are receiving.
    I assume you have some code in the constructor of MyControl (other than the invocation of InitializeComponent) that is throwing an exception. Could you please elaborate on your implementation?
    Some details on the exception like a stack trace, inner exception, etc. would also be helpful.
    We will probably be able to help you better if you could send over your project in a support ticket for debugging purposes.

    All the best,
    Iva
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top