Tags

Hi,

Creating an About page into a Windows Phone 8 application, I thougth it would be interesting to put a hyperlink button for navigating to a URL.

If you try to set a URL by the following way, Visual Studio will throw you a navigation exception:

<HyperlinkButton x:Name="DGualdaHyperlink" 
Content="www.davidgualda.com"
NavigateUri="http://www.davidgualda.com" />

Code Above will go to NavigationFailed:

image

To perform this task there is a very easy way, by using the class “Microsoft.Phone.Tasks.WebBrowserTask”

Steps to follow are:

1.  Asociate a method for clicking event:

<HyperlinkButton x:Name="DGualdaHyperlink" Content="www.davidgualda.com" 
Click="DGualdaHyperlink_Click_1" />

2. In code behind, you will have to add this code:

private void DGualdaHyperlink_Click_1(object sender, RoutedEventArgs e)
{
ShowInBrowser("http://www.davidgualda.com");
}

private void ShowInBrowser(string url)
{
Microsoft.Phone.Tasks.WebBrowserTask wbt = new Microsoft.Phone.Tasks.WebBrowserTask();
wbt.Uri = new Uri(url);
wbt.Show();
}

Just doing this, device will open a browser with the specific url. and clicking back we will comeback to our application.

I hope it helps.

See you.