开发者

WPF Frames - open links in external browser

开发者 https://www.devze.com 2022-12-25 15:04 出处:网络
I have a Frame (used to display a local html f开发者_如何学JAVAile) in a WPF window. I would like that when the user clicks on a link or such, this is opened in an external browser window ( user\'s de

I have a Frame (used to display a local html f开发者_如何学JAVAile) in a WPF window. I would like that when the user clicks on a link or such, this is opened in an external browser window ( user's default web browser).

Any ideas how to go about this please?


Just do it:

private void Frame_Navigating(object sender, NavigatingCancelEventArgs e)
{
    // You should make sure the links are different.
    if (IsExternalLink(e.Uri))
    {
        // open links in extbrowser.
        Process.Start(e.Uri.AbsoluteUri);
        // cancel the event, and Frame cannot perform navigation operation.
        e.Cancel = true;
    }
}

Another solution: ExternalLinks use the Click event instead of the RequestNavigate event.


<TextBlock>
   <Hyperlink NavigateUri="http://www.google.com" TargetName="_top">
      Go Google!
   </Hyperlink>
</TextBlock>


This is a really informative article Launching the Browser from a Hyperlink and goes some to explaining what you need, read through the bullet points of "Browser (XBAP or Loose XAML)".

Setting the TargetName="_self" will open the link in the current frame, which I gather is what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号