Prism.Unity 7.0.0.396 and Xamarin Forms 2.5.0.280555
I just started playing around with Prism with Forms. When navigating 3 deep my third page's viewmodel OnNavigatedTo is not called. Pages 1 and 2 are the same so I am not sure why it doesn't work on Page3.
I can however Navigate from Page 1 to Page 3 and OnNavigatedTo will get called on Page 3. When I try to navigate from page 1 to page2 to page3 it does not.
I have attached a simple repro of my issue in the attached zip file. If anyone can help me figure out what I have done wrong I would greatly appreciate it.
My app.xaml.cs
public partial class App : PrismApplication
{
public App(IPlatformInitializer initializer = null) : base(initializer)
{
}
protected override void OnInitialized()
{
InitializeComponent();
NavigationService.NavigateAsync("HomePage");
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
//Pages
containerRegistry.RegisterForNavigation<HomePage, HomeViewModel>();
containerRegistry.RegisterForNavigation<Page1Page, Page1ViewModel>();
containerRegistry.RegisterForNavigation<Page2Page, Page2ViewModel>();
containerRegistry.RegisterForNavigation<Page3Page, Page3ViewModel>();
}
}
public class HomeViewModel : PageViewModelBase, INavigatedAware
{
INavigationService _navigationService;
public ICommand NavigateToActivityManagementPageCommand { get; private set; }
public ICommand NavigateToPage1PageCommand { get; private set; }
public string SideDrawerHeaderIcon { get; }
public string SideDrawerHeaderTitle { get; }
public string SideDrawerSubHeaderTitle { get; }
public HomeViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
NavigateToPage1PageCommand = new Command(() => NavigateToPage1Page());
}
private void NavigateToPage1Page()
{
_navigationService.NavigateAsync("Page1Page");
}
public void OnNavigatedFrom(NavigationParameters parameters)
{
throw new NotImplementedException();
}
public void OnNavigatedTo(NavigationParameters parameters)
{
throw new NotImplementedException();
}
}
public class Page1ViewModel : PageViewModelBase, INavigatedAware, IDestructible
{
INavigationService _navigationService;
private string _inputResult;
public string InputResult
{
get { return _inputResult; }
set { SetProperty(ref _inputResult, value); }
}
public Page1ViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
NavigateToPage2PageCommand = new Command(NavigateToPage2Page);
}
public Command NavigateToPage2PageCommand { get; private set; }
private void NavigateToPage2Page()
{
var selected = 1;
var parameter = new NavigationParameters();
parameter.Add("selected", selected);
_navigationService.NavigateAsync("Page2Page", parameter);
}
public void OnNavigatedFrom(NavigationParameters parameters)
{
}
public void OnNavigatedTo(NavigationParameters parameters)
{
}
public void Destroy()
{
}
}
public class Page2ViewModel : PageViewModelBase, INavigatedAware, IDestructible
{
INavigationService _navigationService;
public Page2ViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
NavigateToPage3PageCommand = new Command(NavigateToSelectedPage);
}
public void OnNavigatedFrom(NavigationParameters parameters)
{
throw new NotImplementedException();
}
public void OnNavigatedTo(NavigationParameters parameters)
{
}
public Command NavigateToPage3PageCommand { get; private set; }
private void NavigateToSelectedPage()
{
//InputResult = "Waiting for result...";
var SelectedItem = 2;
var parameter = new NavigationParameters();
parameter.Add("selectedItem", SelectedItem);
_navigationService.NavigateAsync("Page3Page", parameter);
}
public void Destroy()
{
}
}
public class Page3ViewModel : PageViewModelBase, INavigatedAware ,IDestructible
{
INavigationService _navigationService;
private string _testText;
public string testText
{
get { return _testText; }
set { SetProperty(ref _testText, value); }
}
public Page3ViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
testText = "Did OnNavigateTo get called?";
}
public async void Back()
{
await _navigationService.GoBackAsync();
}
public void OnNavigatedFrom(NavigationParameters parameters)
{
throw new NotImplementedException();
}
public void OnNavigatedTo(NavigationParameters parameters)
{
var selectedItem = (string)parameters["selectedItem"];
testText = "OnNavigateTo was called!!";
}
public void Destroy()
{
}
}