I'm developing a WP8.1 application who uses MVVM Light. Basically it works fine. Except a strange behavior with the navigation. I have a command in a VM that is bound to the selectionChanged Event of a list:
private void GoToTransactionList()
{
if (SelectedAccount != null)
{
((Frame)Window.Current.Content).Navigate(typeof(TransactionList));
}
}
The View doesn't have any code behind and the whole content is on a user control. This is the VM:
public class TransactionListUserControlViewModel : ViewModelBase
{
private Account SelectedAccount
{
get { return ServiceLocator.Current.GetInstance<AccountDataAccess>().SelectedAccount; }
}
public ObservableCollection<FinancialTransaction> RelatedTransactions
{
get { return ServiceLocator.Current.GetInstance<TransactionDataAccess>().RelatedTransactions; }
}
public RelayCommand LoadRelatedTransactionsCommand { get; private set; }
public TransactionListUserControlViewModel()
{
LoadRelatedTransactionsCommand = new RelayCommand(LoadRelatedTransactions);
}
private void LoadRelatedTransactions()
{
ServiceLocator.Current.GetInstance<TransactionDataAccess>().GetRelatedTransactions(SelectedAccount.Id);
}
public void Dispose()
{
this.Cleanup();
}
}
My Locator looks like this:
public TransactionListUserControlViewModel TransactionListControl
{
get { return new TransactionListUserControlViewModel(); }
}
Or:
public TransactionListUserControlViewModel TransactionListControl
{
get { return ServiceLocator.Current.GetInstance<TransactionListUserControlViewModel>(); }
}
I tried both. But don't change the behavior.
Now, I navigate to the List for the first time I have to click the back button once to navigate back. If i navigate again to the page, I have to click twice and so on. In other words the View won't be disposed but for each time I navigate to the view a new obect is generated. I assume that depends on something who is missing on the VM.
For a better overview I add here the link to the github Repo.
Can anyone tell me what I have forgotten?
Thanks for your help!