Reputation: 33
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.
Upvotes: 3
Views: 6399
Reputation: 1
If you want to use a TextBlock. I use something I ran across and works great for me.
XAML:
< TextBlock >
< Hyperlink NavigateUri="http://yoursite.com" RequestNavigate="Hyperlink_RequestNavigate" >
Click Me
< /Hyperlink >
< /TextBlock >
Code Behind:
private void Hyperlink_RequestNavigate(object sender,
System.Windows.Navigation.RequestNavigateEventArgs e) {
System.Diagnostics.Process.Start(
new System.Diagnostics.ProcessStartInfo(e.Uri.AbsoluteUri)
);
e.Handled = true;
}
===============================
I have seen this alot as the solution but was getting an error at Process.Start. Did some more reading and found out this is best for Web Apps. Whether it is or is not the solution posted above solved my hyperlink issue.
protected void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) {
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
===============================
Upvotes: 0