Navigate to an URL in Windows Phone using HyperlinkButton

Generally , We use the WebBrowserTask in Windows Phone to Navigate to an external URL . Alternatively , one could also use the HyperlinkButton to navigate to an external URL too.

Just set the TargetName =”_blank” and then specify the NavigateUri property of the HyperlinkButton like the below sample sourcecode

<HyperlinkButton Content="HyperlinkButton" Height="100" HorizontalAlignment="Left" Margin="26,62,0,0" Name="hyperlinkButton1" VerticalAlignment="Top" Width="396" Click="hyperlinkButton1_Click" NavigateUri="http://www.developerpublish.com" TargetName="_blank" />

If you dont set http:// before the URL , you will get the error “Cannot navigate to locations relative to a page”.

Navigate to an URL in Windows Phone using HyperlinkButton

Navigate to an URL in Windows Phone using HyperlinkButton

If you dont set the TargetName=”_blank”  , you will get the Navigation Failed error with message “System.ArgumentException: Navigation is only supported to relative URIs that are fragments, or begin with ‘/’, or which contain ‘;component/’.
Parameter name: uri”

Navigate to an URL in Windows Phone using HyperlinkButton - 2

Navigate to an URL in Windows Phone using HyperlinkButton – 2

Leave a Reply