简体   繁体   中英

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>

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM