Nikhil Thaker
Top achievements
Rank 1
Nikhil Thaker
asked on 28 Dec 2010, 02:57 PM
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....
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....
3 Answers, 1 is accepted
0
Hi Nikhil Thaker,
There are a few things worth noting here:
Iva
the Telerik team
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:
- 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.
- 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.
- 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.)
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Nikhil Thaker
Top achievements
Rank 1
answered on 07 Feb 2011, 08:36 AM
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..
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..
0
Hi Nikhil Thaker,
Iva
the Telerik team
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.
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>>