locked
Frame.NavigateTo and RoutedEvent Handlers RRS feed

  • Question

  • Hello All,

    Something interesting has been happening with Frame.NavigateTo navigation and the event handlers being attached to different controls. I wanted to check if there is anyone else having same type of issues.

    So lets say have two pages in my application (e.g. the hub page and the category page).

    When I call

    this.Frame.NavigateTo(typeof(MyLayoutAwareCategoryPage), myParameter) 

    the application first initializes a new instance of the category page and category page instance. The event handlers for the controls (e.g. toggle switches) are in place, everything works out fine.

    However, when I Frame.GoBack to the hub page... And then navigate to the category page yet again using the frame. The category page is instantiated again.However, to my surprise, the routed event handlers are attached twice this time. (i.e. the event handler functions are called twice).

    Anybody out there having same type of an issue? Is there something wrong with this methodology?

    Thanks in advance,

    Can


    Can Bilgin
    Blog CompuSight


    • Edited by Can Bilgin Monday, May 21, 2012 12:45 PM typo
    Monday, May 21, 2012 12:44 PM

Answers

  • This is a bug we identified and the workaround is to remove the extra event handlers by using the "-=" syntax instead of "+=".

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Monday, May 21, 2012 5:42 PM
    Moderator
  • Hey Matt,

    The problem is more complex than just removing the "extra" event handler (Cause there is no extra event handler, somehow it seems the events are being fired from the previous instance of the layoutaware page)... Does not matter however we subscribe to toggled event (manualls, xaml)... It always throws multiple times... And more over, we are supposed to actually use the sender's rectangle and open a context menu, the rectangle goes out of control, starts throwing weird numbers (talking about the first couple of times it is fired). Only finally the last one returns the correct values.

    And yes we do unsubscribe and readd the event handler, tried on constructor. But the same faith.

    The actual solution is to remove the event handler when the first instance of the page is closing (e.g. we are using the SaveState function of the LayoutAware page).


    Can Bilgin
    Blog CompuSight

    • Marked as answer by Can Bilgin Wednesday, May 23, 2012 9:57 AM
    Tuesday, May 22, 2012 11:12 AM

All replies

  • This is a bug we identified and the workaround is to remove the extra event handlers by using the "-=" syntax instead of "+=".

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Monday, May 21, 2012 5:42 PM
    Moderator
  • Thanks Matt... In a way, glad to hear this is a bug.. :) Is there a listing somewhere about the known issues?

    Can Bilgin
    Blog CompuSight

    Monday, May 21, 2012 7:29 PM
  • There's another post that described the problem but I can't find it...

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Monday, May 21, 2012 7:48 PM
    Moderator
  • Hey Matt,

    The problem is more complex than just removing the "extra" event handler (Cause there is no extra event handler, somehow it seems the events are being fired from the previous instance of the layoutaware page)... Does not matter however we subscribe to toggled event (manualls, xaml)... It always throws multiple times... And more over, we are supposed to actually use the sender's rectangle and open a context menu, the rectangle goes out of control, starts throwing weird numbers (talking about the first couple of times it is fired). Only finally the last one returns the correct values.

    And yes we do unsubscribe and readd the event handler, tried on constructor. But the same faith.

    The actual solution is to remove the event handler when the first instance of the page is closing (e.g. we are using the SaveState function of the LayoutAware page).


    Can Bilgin
    Blog CompuSight

    • Marked as answer by Can Bilgin Wednesday, May 23, 2012 9:57 AM
    Tuesday, May 22, 2012 11:12 AM
  • You are correct - I'd forgotten that part.  It's in that other post, wherever it is... :-)


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    Tuesday, May 22, 2012 3:49 PM
    Moderator