janani
janani

Reputation: 31

Adding hyperlink button in XAML with Visual Studio 11 (Windows 8)

I need to add a hyperlink button that directs to a webpage to my metro style apps written with C# and XAML. As in Silverlight, there is no NavigateURI option. Is there any other option to make a hyperlink redirect to a specific webpage?

Upvotes: 3

Views: 6834

Answers (5)

kevinpelgrims
kevinpelgrims

Reputation: 2156

Just in case somebody stumbles upon this: I'm using Visual Studio 2012 RTM on Windows 8 RTM and NavigateURI is back and opens the default metro browser.

Upvotes: 0

Michael
Michael

Reputation: 421

There's a sample in the Sample App Pack that does this.

    // Launch a URI.
    private async void LaunchUriButton_Click(object sender, RoutedEventArgs e)
    {
        // Create the URI to launch from a string.
        var uri = new Uri(uriToLaunch);

        // Launch the URI.
        bool success = await Windows.System.Launcher.LaunchUriAsync(uri);
        if (success)
        {
            rootPage.NotifyUser("URI launched: " + uri.AbsoluteUri, NotifyType.StatusMessage);
        }
        else
        {
            rootPage.NotifyUser("URI launch failed.", NotifyType.ErrorMessage);
        }
    }

Upvotes: 2

Zubair Ahmed
Zubair Ahmed

Reputation: 725

I blogged about wiring up HyperlinkButton in Windows8 XAML to launch internet explorer

http://zubairahmed.net/?p=266

Upvotes: 1

Robert Levy
Robert Levy

Reputation: 29073

Windows.System.Launcher has methods to open the appropriate app for a given Uri or StorageFile. Just wire that up to the click event of your button

Upvotes: 0

Nikhil Agrawal
Nikhil Agrawal

Reputation: 48558

I don't know about Silverlight but in WPF (almost same as SL) we have TextBlock whose inline tag is Hyperlink.

<TextBlock>
    Some text 
    <Hyperlink 
        NavigateUri="http://somesite.com"
        RequestNavigate="Hyperlink_RequestNavigate">
        some site
    </Hyperlink>
    some more text
</TextBlock>

U said "as in silverlight there is no NavigateURI option in this". No Problem.

i didn't knew about this feature of NavigateURI b4. so what i did was when the user clicked on that link it called the browser to open my requested link. In mouse over i changed cursor to look like hand and text color as red and on mouse leave back to default color (Blue) and cursor (Arrow).

I think u got my point.

Upvotes: 1

Related Questions