Click here to Skip to main content
15,064,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to add hyperlink control to textblock so that i can add a link in textblock
i want it to be done programatically

What I have tried:

private void Text(double x, double y, string text, Color color)
        {
            Hyperlink h = new Hyperlink();
            
            
            
            TextBlock textBlock = new TextBlock();
            
            textBlock.Text = text;
            
            textBlock.Foreground = new SolidColorBrush(color);
            Canvas.SetLeft(textBlock, x);
            Canvas.SetTop(textBlock, y);
            mycanvas.Children.Add(textBlock);

        }
Posted
Updated 1-Apr-21 6:07am
Comments
Graeme_Grant 12-Sep-17 9:56am
   
Is this a code-behind or MVVM project? Also, why are you using a Canvas control?

1 solution

Add it to the Inlines[^] collection:
C#
var h = new Hyperlink();
h.Inlines.Add(text);

var textBlock = new TextBlock();
textBlock.Inlines.Add(h);
   
Comments
Graeme_Grant 12-Sep-17 23:01pm
   
5'd
srilekhamenon 14-Sep-17 5:40am
   
Thanku

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900