mvvm - NavigationPage is incremented for each HyperlinkButton click (Silverlight) -


this 1 of questions answer should obvious miss. still, can't seem figure out why "play&learn" application behaves way does.

on mainpage.xaml have stackpanel containing several hyperlinkbuttons navigates set of navigationpages. there navigationframe urimapper hold "pages".

<stackpanel background="black" orientation="horizontal" grid.row="0">     <hyperlinkbutton name="home"                       targetname="mainpageframe" navigateuri="/home"                      foreground="white" fontweight="bold" content="home" />     <hyperlinkbutton name="users"                       targetname="mainpageframe" navigateuri="/users"                      foreground="white" fontweight="bold" content="users" />     <hyperlinkbutton name="store" foreground="white" fontweight="bold" content="store"                      targetname="mainpageframe" navigateuri="/stores"/>           </stackpanel> <navigation:frame x:name="mainpageframe" grid.row="1" source="/home" horizontalalignment="stretch" verticalalignment="stretch" journalownership="automatic">     <navigation:frame.urimapper>         <urimapper:urimapper>             <urimapper:urimapping uri="/{pagename}" mappeduri="/views/{pagename}.xaml"/>         </urimapper:urimapper>     </navigation:frame.urimapper> </navigation:frame> 

here's problem. when go , forth between pages (i.e: click on stores, users , on stores) 2 stores pages created. though not visible in application @ first glance problem materialize when child window opened stores page.

as use mvvm light messaging notify child window should open, ... 2 child windows (or 1 each time have entered stores navigation page hyperlinkbuttons).

i presumed while clicking on hyperlink buttons, have 1 navigationpage ..or @ least current destructed while leaving navpage.

what obvious thing missing?

the problem lies in registration of message handler. there known problem mvvm light messenger, results in object handling message not being released propperly.

the solution quite simple - assuming view handles message - code behind should this:

public storeview() {     messenger.default.register<notificationmessage>(this, (m) => {         // message handling     });      initializecomponent(); } 

now modify looks similar this:

public storeview() {     messenger.default.register<notificationmessage>(this, (m) => {         // message handling     });      initializecomponent();      this.unloaded += (sender, args) => {         messenger.default.unregister(this);     }; } 

the code in unloaded event ensures message handler unregistered. messages in viewmodels ensure cleanup method called.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -