HyperlinkButton HyperlinkButton HyperlinkButton Class

Represents a button control that functions as a hyperlink.

Syntax

Declaration

public class HyperlinkButtonpublic class HyperlinkButtonPublic Class HyperlinkButton
<HyperlinkButton .../>
-or-
<HyperlinkButton>stringContent</HyperlinkButton>
-or-
<HyperlinkButton>
    singleObject
</HyperlinkButton>

Inheritance Hierarchy

Inherited Members

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Tag
Tag
Tag
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Remarks

HyperlinkButton is a button that appears as marked up text.

Hyperlink button

Note

By default, the HyperlinkButton appears as underlined text when you set a string as the value for the Content property.

The text does not appear underlined in the following cases:

  • You set a TextBlock as the value for the Content property, and set the Text property on the TextBlock.
  • You re-template the HyperlinkButton and change the name of the ContentPresenter template part. If you need a button that appears as non-underlined text, consider using a standard Button control and applying the built-in TextBlockButtonStyle system resource to its Style property.

There are two ways that you can add a hyperlink to a XAML app. Hyperlink and HyperlinkButton have the similar purpose of enabling a user to launch a specific URI using a separate browser app.+ Use an inline Hyperlink text element inside of a text control. A Hyperlink element flows with other text elements and you can use it in any InlineCollection. For more info, see Hyperlink.

To use the hyperlink to navigate to a Uniform Resource Identifier (URI), set the NavigateUri property. When a user clicks or taps the HyperlinkButton, the specified Uniform Resource Identifier (URI) opens in the default browser. The default browser runs in a separate process from your app.

Tip

You don't have to use http: or https: schemes. You can use schemes such as ms-appx:, ms-appdata:, or ms-resources:, if there's resource content at these locations that's appropriate to load in a browser. However, the file: scheme is specifically blocked. For more info, see URI schemes.

When a user clicks the HyperlinkButton, the value of the NavigateUri property is passed to a system handler for Uniform Resource Identifier (URI) types and schemes. The system then launches the app that is registered for the scheme of the Uniform Resource Identifier (URI) provided for NavigateUri.

If you don't want the HyperlinkButton to load content in a default Web browser (and don't want a browser to appear), then don't set a value for NavigateUri. Instead, handle the Click event, and write code that does what you want.

Handle the Click event

Use the Click event for actions other than launching a Uniform Resource Identifier (URI) in a browser, such as navigation within the app. For example, if you want to load a new app page rather than opening a browser, call a Navigate(Windows.UI.Xaml.Interop.TypeName,System.Object,Windows.UI.Xaml.Media.Animation.NavigationTransitionInfo) method within your Click event handler to navigate to the new app page. If you want an external, absolute Uniform Resource Identifier (URI) to load within a WebView control that also exists in your app, call Navigate(Windows.Foundation.Uri) as part of your Click handler logic.

You don't typically handle the Click event as well as specifying a NavigateUri value, as these represent two different ways of using the Hyperlink element. If your intent is to open the URI in the default browser, and you have specified a value for NavigateUri, don't handle the Click event. Conversely, if you handle the Click event, don't specify a NavigateUri.

There's nothing you can do within the Click event handler to prevent the default browser from loading any valid target specified for NavigateUri; that action takes place automatically (asynchronously) when the hyperlink is activated and can't be canceled from within the Click event handler.

Examples

Here's a HyperlinkButton as declared in XAML. It declares a string value for Content and also a NavigateUri value.

<HyperlinkButton Content="www.microsoft.com" NavigateUri="http://www.microsoft.com"/>

Constructors summary

Initializes a new instance of the HyperlinkButton class.

Properties summary

Gets or sets the Uniform Resource Identifier (URI) to navigate to when the HyperlinkButton is clicked.

Identifies the NavigateUri dependency property.

Constructors

  • HyperlinkButton()
    HyperlinkButton()
    HyperlinkButton()
    HyperlinkButton()

    Initializes a new instance of the HyperlinkButton class.

    public HyperlinkButton()public HyperlinkButton()Public Function HyperlinkButton() As

Properties

  • NavigateUri
    NavigateUri
    NavigateUri
    NavigateUri

    Gets or sets the Uniform Resource Identifier (URI) to navigate to when the HyperlinkButton is clicked.

    public Uri NavigateUri { get; set; }public Uri NavigateUri { get; set; }Public ReadWrite Property NavigateUri As Uri
    <HyperlinkButton NavigateUri="uriString"/>
    

    Property Value

    Remarks

    When a user clicks or otherwise invokes a HyperlinkButton, it opens the URI you specified for the NavigateUri property in the default browser.

    You don't have to use http: or https: schemes for the URI. You can use schemes such as ms-appx:, ms-appdata:, or ms-resources:, if there's resource content at these locations that's appropriate to load in a browser. However, the file: scheme is specifically blocked. For more info, see URI schemes.

    HyperlinkButton is a control, so it has input events such as Tapped, and it's a ButtonBase subclass so it also has a Click event. You don't typically specify a value for NavigateUri and also handle input events that are interpreted as clicking the HyperlinkButton. The action of opening the NavigateUri in a default browser is a system action that takes place without requiring any event handling. If your intent is that the HyperlinkButton should load a specified URI within a WebView control that's also part of your app, then don't specify a value for NavigateUri. Handle the Click event instead, and call Navigate(Windows.Foundation.Uri), specifying the URI to load.

    Examples

    Here's a HyperlinkButton as declared in XAML. It declares a string value for Content and also a NavigateUri value.

    <HyperlinkButton Content="www.microsoft.com" NavigateUri="http://www.microsoft.com"/>
    
  • NavigateUriProperty
    NavigateUriProperty
    NavigateUriProperty
    NavigateUriProperty

    Identifies the NavigateUri dependency property.

    public static DependencyProperty NavigateUriProperty { get; }public static DependencyProperty NavigateUriProperty { get; }Public Static ReadOnly Property NavigateUriProperty As DependencyProperty

    Property Value

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.Controls.dll