0

I use HyperLinkButton and add method in c# code for click for him.

Code method:

void btnViewURL_Click(object sender, RoutedEventArgs e)
{
         if (string.IsNullOrWhiteSpace(viewURL) == false
         && this.decisionViewModel.IsURLValid(viewURL))
         {
             System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(viewURL, UriKind.Absolute), "_blank");
         }
}

This code worked in ie but not in Safari.

After I try to use NavigateUrl property in xaml. I added binding, but this method does not work too in Safari. If I set plain text url (for example - "https://google.com" without binding so then Safari opened link.

<HyperlinkButton Margin="8,0,0,0" x:Name="linkStaticURL" 
    NavigateUri="{Binding viewURL}"
    TargetName="_blank">
                <TextBlock Text="Reader"</TextBlock>
</HyperlinkButton>

How can I solve this problem?

1 Answers1

0

You could use Process.Start to open the URL in your default browser:

void btnViewURL_Click(object sender, RoutedEventArgs e)
{
    if (string.IsNullOrWhiteSpace(viewURL) == false)
      && this.decisionViewModel.IsURLValid(viewURL))
    {
        System.Diagnostics.Process.Start(viewURL);
    }
}

If you want to launch a specific web browser, you could pass its location to the same method as suggested here:

Launch Web URL in NON-default browser

And besides setting a NavigateUri you should also handle the RequestNavigate event:

Example using Hyperlink in WPF

mm8
  • 163,881
  • 10
  • 57
  • 88