locked
Hyperlink NavigateUri in a TextBloick - tapping doesn't do anything? RRS feed

  • Question

  • I'm using the Hyperlink in a TextBlock that got added in Windows 8.1:

    <TextBlock Style="{StaticResource BodyTextBlockStyle}" Padding="0,12,0,0">
                    To help you use the app,
                    <Hyperlink NavigateUri="ms-appx:///Assets/UserGuide.pdf" > a user guide is available.</Hyperlink>
    </TextBlock>
    

    However, tapping on the link when displayed in the app doesn't result in anything happening. I've got other uses of Hyperlink including a straightforward HTTP URL and a mailto: URL. These don't do anything either.

    What am I misunderstanding?

    Thanks.

    Sunday, December 1, 2013 12:42 PM

Answers

  • Thank you for providing your sample.

    I have figured out what the problem was. Although my GridView was empty, it was over the top of the StackPanel and so no clicks were getting through. Moving the StackPanel down the XAML solved it.

    Weird - I would never have thought that an empty GridView would still fill the screen.

    • Marked as answer by Philip Colmer Tuesday, December 10, 2013 11:30 AM
    Tuesday, December 10, 2013 11:29 AM

All replies

  • Hi Philip,

    Read the remark section from Hyperlink documentation: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.documents.hyperlink.aspx Probably Tap is not a good choice for Hyperlink, instead Click event should be used.

    Because a Hyperlink is not a UIElement it does not have the set of UI element  input events such as Tapped, PointerPressed and so on. Instead, a Hyperlink has its own Click event. The system handles all input actions that should invoke the Hyperlink actions  and fires Click in response.

    And if you want to open a pdf file, I think the best way is to use "Windows.System.Launcher.LaunchFileAsync()", see this for more information: How to launch the default app for a file.

    --James

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, December 2, 2013 1:09 AM
    Moderator
  • Hi Philip,

    Read the remark section from Hyperlink documentation: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.documents.hyperlink.aspx Probably Tap is not a good choice for Hyperlink, instead Click event should be used.

    Because a Hyperlink is not a UIElement it does not have the set of UI element  input events such as Tapped, PointerPressed and so on. Instead, a Hyperlink has its own Click event. The system handles all input actions that should invoke the Hyperlink actions  and fires Click in response.

    And if you want to open a pdf file, I think the best way is to use "Windows.System.Launcher.LaunchFileAsync()", see this for more information: How to launch the default app for a file.

    --James

    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Sorry, you misunderstood what I meant by me saying "tapping on the link". I meant when I physically tap on the UI with my finger.

    The remarks for the class definitely say that the Hyperlink object should handle the Click event itself and therefore navigate to the Uri specified. However, it doesn't seem to be doing that, even for more conventional HTTP URIs and not the file URI.

    Hence my confusion/frustration.

    Regards

    Philip

    Monday, December 9, 2013 9:00 AM
  • i used the xaml with an http url and works great. where did you placed it? can hittest be turned off in the container?

    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, December 9, 2013 9:41 AM
  • I've placed it in a StackPanel:

        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.ChildrenTransitions>
                <TransitionCollection>
                    <EntranceThemeTransition/>
                </TransitionCollection>
            </Grid.ChildrenTransitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            
            <!-- Display intro stuff but not if narrow view -->
            <StackPanel Name="IntroDisplay" Grid.Row="1" Margin="116,0,116,46" >
                <TextBlock Style="{StaticResource GroupHeaderTextStyle}">
                    Welcome
                </TextBlock>
                <TextBlock Style="{StaticResource BodyTextBlockStyle}" Padding="0,12,0,0">
                    This is some text. If you have any feedback - good or bad - or any suggestions on features
                    you would like to see in the app, please either send an email to
                    <Hyperlink NavigateUri="mailto:support@xxx.yyy"> support@xxx.yyy </Hyperlink>
                    or go to
                    <Hyperlink NavigateUri="http://xxx.yyy.zzz/"> our page on UserVoice.</Hyperlink>
                </TextBlock>
                <TextBlock Style="{StaticResource BodyTextBlockStyle}" Padding="0,12,0,0">
                    To help you use the app,
                    <Hyperlink NavigateUri="ms-appx:///Assets/UserGuide.pdf" > a user guide is available.</Hyperlink>
                    Clicking on the link should open the guide in Reader, allowing you to have the guide side-by-side with the app.
                </TextBlock>
            </StackPanel>
    

    I'm afraid I don't understand your second question.

    Monday, December 9, 2013 9:48 AM
  • is working here http://sdrv.ms/1f18jBQ

    do you have a reproduceable demo project that you can share?


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Monday, December 9, 2013 9:53 AM
  • Thank you for providing your sample.

    I have figured out what the problem was. Although my GridView was empty, it was over the top of the StackPanel and so no clicks were getting through. Moving the StackPanel down the XAML solved it.

    Weird - I would never have thought that an empty GridView would still fill the screen.

    • Marked as answer by Philip Colmer Tuesday, December 10, 2013 11:30 AM
    Tuesday, December 10, 2013 11:29 AM