HypreLink in WPF User control.
-
Hey everyone, I am doing my first WPF User control. I am trying to get my hyperlink to open a new IE browser when I press a on my "link label". my code sampel; When I press on the HyperLink nothing happen. This is a sampel of my code behid class; namespace WpfShowResultsControl { public partial class GetSearchResultUserControl : UserControl { public GetSearchResultUserControl() { InitializeComponent(); } void HandleRequestNavigate(object sender, RoutedEventArgs e) { string navigateUri = hl.NavigateUri.ToString(); Process.Start(new ProcessStartInfo(navigateUri)); e.Handled = true; } } } I have tried many eksampels on diffrent forums and I cannot get it works. I have also tried like this :( :confused: In my code behind class, I cannot use hl, it looks like it does not exist. What can I do to get hl useable? Could any one please advice me what I am missin in my code. Many thanks in advance! :confused::confused:
-
Hey everyone, I am doing my first WPF User control. I am trying to get my hyperlink to open a new IE browser when I press a on my "link label". my code sampel; When I press on the HyperLink nothing happen. This is a sampel of my code behid class; namespace WpfShowResultsControl { public partial class GetSearchResultUserControl : UserControl { public GetSearchResultUserControl() { InitializeComponent(); } void HandleRequestNavigate(object sender, RoutedEventArgs e) { string navigateUri = hl.NavigateUri.ToString(); Process.Start(new ProcessStartInfo(navigateUri)); e.Handled = true; } } } I have tried many eksampels on diffrent forums and I cannot get it works. I have also tried like this :( :confused: In my code behind class, I cannot use hl, it looks like it does not exist. What can I do to get hl useable? Could any one please advice me what I am missin in my code. Many thanks in advance! :confused::confused:
hi you can try this: make an click event on you textblok. and in you click event call:
System.Diagnostics.Process.Start("http://www.google.de");
-
Hey everyone, I am doing my first WPF User control. I am trying to get my hyperlink to open a new IE browser when I press a on my "link label". my code sampel; When I press on the HyperLink nothing happen. This is a sampel of my code behid class; namespace WpfShowResultsControl { public partial class GetSearchResultUserControl : UserControl { public GetSearchResultUserControl() { InitializeComponent(); } void HandleRequestNavigate(object sender, RoutedEventArgs e) { string navigateUri = hl.NavigateUri.ToString(); Process.Start(new ProcessStartInfo(navigateUri)); e.Handled = true; } } } I have tried many eksampels on diffrent forums and I cannot get it works. I have also tried like this :( :confused: In my code behind class, I cannot use hl, it looks like it does not exist. What can I do to get hl useable? Could any one please advice me what I am missin in my code. Many thanks in advance! :confused::confused:
From [^] "Hyperlink is "navigation service" aware, which means it can work properly as you expect in navigation application(using NavigationWindow, Frame which can provide navigation service). In standalone non-navigation application, you can hook up to its Click event, and implement the navigation logic there." So, in your case you will need to use click handler as suggested ^^
-
From [^] "Hyperlink is "navigation service" aware, which means it can work properly as you expect in navigation application(using NavigationWindow, Frame which can provide navigation service). In standalone non-navigation application, you can hook up to its Click event, and implement the navigation logic there." So, in your case you will need to use click handler as suggested ^^
I hope you found this useful : private void Windows_Loaded(object sender, RoutedEventArgs e) { AddHandler(Hyperlink.ClickEvent, (RoutedEventHandler)Hyperlink_Click); } private void Hyperlink_Click(object sender, RoutedEventArgs e) { if (e.OriginalSource is Hyperlink) { Process.Start((e.OriginalSource as Hyperlink).NavigateUri.AbsoluteUri); e.Handled = true; } }