locked
8.1 Document.Hyperlink events not firing RRS feed

  • Question

  • I migrated my app to 8.1/2013 in order to take advantage of the new Hyperlink Inline type. A portion of the code is below. I'm just writing out paragraphs and identified words are hyperlinked.

    However, the click event never fires. In the UI while running, the links show up properl: hover changes the color and the hand pointer shows.

    I also tried to add a Uri to the NavigateUri property and that doesn't fire either.

    What am I missing?

            private void AddRuns(Paragraph p, string content)
            {
    			foreach ( var r in MarkupHelper.ParseRuns( content ) )
    			{
    				var run = new Run
    				{
    					Text = r.Text,
    					FontSize = 22,
    					FontWeight = r.Bold ? FontWeights.Bold : FontWeights.Normal,
    					FontStyle = r.Italic ? FontStyle.Italic : FontStyle.Normal
    				};
    
    				p.Inlines.Add( ApplyHyperlinks( run, r ) );
    			}
    
            }
    
    		private Inline ApplyHyperlinks( Run run, Shadow8.Common.MarkupHelper.RunInfo runInfo )
    		{
    			if ( runInfo.Noun )
    			{
    				var hyperlink = new Hyperlink();
    				hyperlink.Inlines.Add( run );
    
                    hyperlink.Click += hyperlink_Click;
    
    				return hyperlink;
    			}
    
    			return run;
    		}
    
            public void hyperlink_Click(Hyperlink sender, HyperlinkClickEventArgs args)
            {
                InlineCollection inlines = sender.Inlines;
                Run linkRun = (Run)inlines[0];
                this.CommandBuilderControl.Process_Word(linkRun.Text);
            }


    Friday, November 15, 2013 5:47 PM

Answers

  • (huge sigh)

    I found it and embarrassingly don't know how I missed this in the 20 reviews of the code.

    The RichTextBlock had IsTapEnabled="False".

    This issue is resolved.

    • Marked as answer by ChicagoDave Saturday, November 30, 2013 8:30 PM
    Saturday, November 30, 2013 8:29 PM

All replies

  • Hi Dave,

    I'm not sure the problem is in the code snippet you included. I just ran essentially the same code as your ApplyHyperLinks in a test app (modified to work without your helper functions) and the HyperLink triggered both Click and NavigateUri as expected. Do you have some other control that could be intercepting the PointerPressed or Released events?

    Can you reproduce this in a minimal sample app that you can share on your SkyDrive?

    --Rob

    Friday, November 15, 2013 7:25 PM
    Moderator
  • Any chance I could add you to my tfs online project for a bit to see all the code? I'm not asking you need to write code or anything, but maybe seeing it all will help identify the issue. One of my problems with dynamic xaml is that it's so difficult to debug. If there were a way to see the generated xaml, it would make life a lot easier.

    David

    Friday, November 15, 2013 8:56 PM
  • Nevermind...I didn't write all of this code. You were dead on. I found this...and when I click a Hyperlink, it breaks in here. Hopefully I can figure out the issue from here.

    Thanks for the tip.

            private void CoreWindow_PointerPressed(CoreWindow sender,
                PointerEventArgs args)
            {
                var properties = args.CurrentPoint.Properties;
    
                // Ignore button chords with the left, right, and middle buttons
                if (properties.IsLeftButtonPressed || properties.IsRightButtonPressed ||
                    properties.IsMiddleButtonPressed) return;
    
                // If back or foward are pressed (but not both) navigate appropriately
                bool backPressed = properties.IsXButton1Pressed;
                bool forwardPressed = properties.IsXButton2Pressed;
                if (backPressed ^ forwardPressed)
                {
                    args.Handled = true;
                    if (backPressed) this.GoBack(this, new RoutedEventArgs());
                    if (forwardPressed) this.GoForward(this, new RoutedEventArgs());
                }
            }


    • Marked as answer by ChicagoDave Friday, November 15, 2013 9:03 PM
    • Unmarked as answer by ChicagoDave Friday, November 15, 2013 10:35 PM
    Friday, November 15, 2013 9:03 PM
  • Well, it looks like one of my devs implemented this:

    https://github.com/joelmartinez/Khan-Academy-for-WinRT/blob/master/KhanAcademy/Common/LayoutAwarePage.cs

    ...and I'm still trying to figure out how to allow Hyperlink events to pass through it...

    David C.


    Friday, November 15, 2013 10:37 PM
  • Can you upload a repro of the issue in a sample project to SkyDrive?

    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Tuesday, November 26, 2013 4:50 PM
    Moderator
  • So far I can't recreate the problem with a sample. I've ruled out that LayoutAwarePage is the primary cause, but something is still blocking clicks (and mousewheel actions).

    I'm just ripping things out until I figure it out.

    David

    Saturday, November 30, 2013 5:39 PM
  • (huge sigh)

    I found it and embarrassingly don't know how I missed this in the 20 reviews of the code.

    The RichTextBlock had IsTapEnabled="False".

    This issue is resolved.

    • Marked as answer by ChicagoDave Saturday, November 30, 2013 8:30 PM
    Saturday, November 30, 2013 8:29 PM