Sam
Sam

Reputation: 51

How can I create a hyperlink in C# code instead of XAML

How can I create a hyper link in C# code that looks like the following in XAML?:

<TextBlock>
    <Hyperlink Click="HyperLinkClick">New Hyperlink</Hyperlink>
</TextBlock>

Upvotes: 2

Views: 6177

Answers (1)

dtb
dtb

Reputation: 217411

MSDN usually has very good examples. Combining the examples for TextBlock and Hyperlink:

TextBlock textBlock1 = new TextBlock();
Run run3 = new Run("Link Text.");

Hyperlink hyperl = new Hyperlink(run3);
hyperl.NavigateUri = new Uri("http://search.msn.com");

textBlock1.Inlines.Add(hyperl);

Upvotes: 4

Related Questions