开发者

WPF Frames - open links in external browser

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜