Build hyperlink in wpf c #
3 answers
Use a HyperlinkButton, not a hyperlink (which is meant to be used in a FlowDocument that has Inlines inside)
HyperlinkButton has a Content property as a content property.
So:
TextBlock tb = new TextBlock();
// set tb properties
HyperlinkButton hlb = new HyperlinkButton();
// set hlb properties
hlp.Content = tb;
0
a source to share
If you want to use TextBlock. I am using what I ran into and works great for me.
XAML:
< TextBlock >
< Hyperlink NavigateUri="http://yoursite.com" RequestNavigate="Hyperlink_RequestNavigate" >
Click Me
< /Hyperlink >
< /TextBlock >
Code for:
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've seen this a lot as a solution, but was getting an error in Process.Start. Have done some reading and figured out what is the best for web applications. Whether this solution or not the solution above solved my hyperlink problem.
protected void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e) {
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
e.Handled = true;
}
===============================
0
a source to share