I like to change the default way of following link in RichtextEditor.
Currently the default is Ctrl + Click. But I want to change it as direct Click with changing of mouse shape to hand finger-like.
thanks a lot in advance
Hello James.Jeon,
You can call Process.Start method to open a link when you click hyperlink text.
private void editor1_PreviewMouseDown(object sender, MouseButtonEventArgs e) { var adornmentLayer = e.OriginalSource as AdornmentLayer; if(adornmentLayer != null) { Process.Start(targetUrl); e.Handled = true; } }
For the mouse cursor, you can change the style by setting Mouse.OverrideCursor.
private void editor1_MouseMove(object sender, MouseEventArgs e) { var adornmentLayer = e.OriginalSource as AdornmentLayer; if (adornmentLayer != null) { Mouse.OverrideCursor = Cursors.Hand; } else { Mouse.OverrideCursor = Cursors.Arrow; } }
Please refer to the attached sample for details.
Best regards,Yuki MitaDeveloper Support EngineerInfragistics Inc.www.infragistics.com/support
Thank you so much about your guide.
May I ask one more thing?
In my program, I subscribe XamRichTextEditor.HyperlinkExecuting event to use Uri property of HyperlinkExecutingEventArgs because I want different actions when user click the hyperlink.
I don't know How can I pass the Uri String into text_PreviewMouseDown() cause it argument is not HyperlinkExecutingEventArgs but MouseButtonEventArgs.
Please let me know how I can do this.
Below are snippet what I want to do.
// MainWindow Code-Behind
public MainWindow()
{
InitializeComponent();
richText.HyperlinkExecuting += richText_HyperlinkExecuting;
}
private void richText_HyperlinkExecuting(object sender, HyperlinkExecutingEventArgs s)
if (e.Uri.StartsWith("AAA")
DoSomeAction();
if (e.Uri.StartsWith("BBB")
DoAnotherAction();
e.Cancel = true;
To Sum it up, I like to call hyperlinkExecuting Event with direct click (not ctrl + click) with Cursors.Hand.
Thank you so much.
You can handle MouseLeftButtonUp event and get which link is clicked, and then write your business logic based on the clicked link.
private void xamRichTextEditor1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { var editor = sender as XamRichTextEditor; if (editor == null) { return; } var docSpan = editor.Selection.DocumentSpan; var paragraphs = editor.Document.GetParagraphs(docSpan); if (paragraphs.First().ChildNodes == null) { return; } var hyperlink = paragraphs.First().ChildNodes.First() as HyperlinkNode; if (hyperlink != null) { if (hyperlink.Uri.Contains("forums")) { //DoSomeAction(); Process.Start(hyperlink.Uri); } else { //DoAnotherAction(); Process.Start(hyperlink.Uri); } } }
If you have any question with this, please let me know.