Take the 2-minute tour ×

This is probably one of those questions where the answer really should be too obvious for any to miss. Still, I can't seem to figure out why my "play&learn" application behaves the way it does.

On my Mainpage.xaml I have a StackPanel containing several HyperlinkButtons which navigates to a set of NavigationPages. There is also a NavigationFrame with a UriMapper to hold the "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"/>          
<navigation:Frame x:Name="MainPageFrame" Grid.Row="1" Source="/Home" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" JournalOwnership="Automatic">

Here's the problem. When I go back and forth between the pages (i.e: click on Stores, Users and back on Stores) then two Stores pages are created. Though not visible in the application at first glance the problem materialize itself when I a child window is opened from the Stores Page.

As I use MVVM light messaging to notify that the child window should open, ... I get two child windows (or one for each time I have entered the stores navigation page from the hyperlinkbuttons).

I presumed that while clicking on the Hyperlink buttons, you would only have one NavigationPage ..or at least the current was destructed while leaving the navpage.

What clearly obvious thing am I missing?

share|improve this question
How are you handling the messages? It may well be the case that one window (reused) is having a handlers added repeatedly. Can you provide code for the stores page? To avoid this always remove a handler before adding one it in code (just in case the code runs twice). –  TrueBlueAussie Jun 30 '11 at 20:04

1 Answer 1

up vote 2 down vote accepted

The problem lies most likely in the registration of the message handler. There is a known problem with the MVVM Light Messenger, that results in the object handling a message not being released propperly.

The solution is quite simple - assuming that your view handles the message - your code behind should look something like this:

public StoreView() {
    Messenger.Default.Register<NotificationMessage>(this, (m) => {
        // some message handling


Now modify it so it looks similar to this:

public StoreView() {
        // some message handling


    this.Unloaded += (sender, args) => {

The code in the unloaded event ensures that the message handler is properly unregistered. For messages in ViewModels ensure that the Cleanup method is called.

share|improve this answer
Thank you! That solved my issue –  Kman Jul 12 '11 at 17:30

Your Answer


