0% found this document useful (0 votes)
35 views3 pages

How To Create Hyperlink Inside Textblock From Codebehind

The document provides guidance on creating a Hyperlink within a TextBlock in WPF using code-behind. It includes example code that demonstrates how to add a Hyperlink to a TextBlock's Inlines collection. Additionally, it addresses a common question about displaying text instead of the URI in the hyperlink.

Uploaded by

Doctor Ammooor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views3 pages

How To Create Hyperlink Inside Textblock From Codebehind

The document provides guidance on creating a Hyperlink within a TextBlock in WPF using code-behind. It includes example code that demonstrates how to add a Hyperlink to a TextBlock's Inlines collection. Additionally, it addresses a common question about displaying text instead of the URI in the hyperlink.

Uploaded by

Doctor Ammooor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

how to create Hyperlink inside textblock from codebehind

This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use. Learn more

SIGN IN

get started for free


GALLERY MSDN LIBRARY FORUMS

Ask a question Search related threads Search forum questions


Submit

Quick access

Answered by: how to create Hyperlink inside textblock from


codebehind
.NET Framework > Windows Presentation Foundation (WPF)

Question

the xaml code is

<Expander>

<StackPanel>
0
<TextBlock>
Sign in
to vote
<Hyperlink NavigateUri="someurl">hi</Hyperlink>

</TextBlock>

</StackPanel>

</Expander>

i need the same to be done from my code behind.

If i pass the entire Hyperlink tag as Text to textblock its displayed in same tag format.

I tried passing inlines to TextBlock it doesn't work.

Wednesday, September 27, 2006 1:18 AM

Reply | Quote

Answers

you can do

TextBlock t = new TextBlock();

0
Sign in Run ln = new Run("some link");

file:///H/downloads1/how%20to%20create%20Hyperlink%20inside%20textblock%20from%20codebehind.htm[PM ۰۷:۳۸:۳۹ ۱۸/۱۰/۱۸]


how to create Hyperlink inside textblock from codebehind

to vote

t.Inlines.Add(new Hyperlink(ln));

c1.Children.Add(t);(c1 is a canvas)

Wednesday, September 27, 2006 2:13 AM Moderator

Reply | Quote

All replies

you can do

TextBlock t = new TextBlock();

0
Sign in Run ln = new Run("some link");
to vote

t.Inlines.Add(new Hyperlink(ln));

c1.Children.Add(t);(c1 is a canvas)

Wednesday, September 27, 2006 2:13 AM Moderator

Reply | Quote

Thank you

Wednesday, September 27, 2006 4:31 AM

Reply | Quote
0
Sign in
to vote

This may be a stupid question, because I am a XAML newbie, but in the example above, how do you
display the text (i.e - "hi") rather than the uri in the hyperlink from code-behind?

Wednesday, February 20, 2008 6:15 PM


0 Reply | Quote
Sign in
to vote

This may be a stupid question, because I am a XAML newbie, but in the example above, how do you display
the text (i.e - "hi") rather than the uri in the hyperlink from code-behind?

0 HyperLink hl = new HyperLink();


Sign in hl.Inlines.Add(new TextBlock { Text = "hi" });
to vote

Friday, July 8, 2011 3:23 PM

file:///H/downloads1/how%20to%20create%20Hyperlink%20inside%20textblock%20from%20codebehind.htm[PM ۰۷:۳۸:۳۹ ۱۸/۱۰/۱۸]


how to create Hyperlink inside textblock from codebehind

Reply | Quote

DEV CENTERS RELATED SITES CONNECT DEVELOPER RESOURCES

Windows Visual Studio Forums Code samples


Office Visual Studio Integrate Blog Documentation
More... VSIP Program Facebook Downloads
Microsoft .NET LinkedIn Products & extensions for Visual Studio
Microsoft Azure Stack Overflow REST APIs
Twitter Testing tools for web developers
Visual Studio Events Videos and tutorials
YouTube Virtual Labs

United States © 2018 Microsoft Terms of Use Trademarks Privacy Statement Site Feedback
(English)

file:///H/downloads1/how%20to%20create%20Hyperlink%20inside%20textblock%20from%20codebehind.htm[PM ۰۷:۳۸:۳۹ ۱۸/۱۰/۱۸]

You might also like