tags:

views:

163

answers:

2

how can i insert a TextBlock control in a Hyperlink in c# coding. similar to <TextBlock> <Hyperlink>a</Hyperlink></textblock in C#. i'm unable to find content property in Hyperlink. Thanks in advance.

A: 

Use an HyperlinkButton, not an Hyperlink (which is meant to be used in a FlowDocument, with Inlines inside)

HyperlinkButton has the Content property as content property.

So:

TextBlock tb = new TextBlock();
// set tb's properties

HyperlinkButton hlb = new HyperlinkButton();
// set hlb's properties
hlp.Content = tb;
Timores
hi Timores, unable to find HyperlinkButton in System.Windows.Controls
fad
It is in the System.Windows assembly. See http://msdn.microsoft.com/en-us/library/system.windows.controls.hyperlinkbutton(VS.95).aspx
Timores
HyperlinkButton is only a Silverlight control. not present in WPF
Simon_Weaver
+2  A: 

Try to use Inlines to add Hyperlink to TextBlock and to add text to HyperLink

TextBlock textBlock = new TextBlock();
Hyperlink link = new Hyperlink();
link.Inlines.Add("Click me");
textBlock.Inlines.Add(link);
Hun1Ahpu
Thanks Hun1Ahpu. it works.
fad