I have a Prism Xamarin.Forms App created with the Prism Template Pack (2.0.7). All packages are up to date:
- Xamarin.Forms v2.5.0.91635
- Xamarin.Android.* v26.1.0.1
- Prism.DryIoc.Forms v7.0.0.168-pre (Could not update to v7.0.0.269-pre due to a NullReferenceException in Android Renderer on startup, however my main application is using 269-pre without that problem)
I hosted the sample Application on https://github.com/dernippel/PrismNavApp
I have the following components:
- Module "Attachments" (a Prism Module)
- Module "Viewer" (a Prism Module)
- Service "AttachmentService" registered with the Container with an Interface as Singleton
They should do this:
- The AttachmentsPage (from the AttachmentsModule) lists some objects
- Selecting one Attachment
- AttachmentPageViewModel calls the "OpenAttachment"-Method of the Attachment Service
- The Method determines the correct ViewerPage by type and uses the Prism-NavigationService to navigate directly to the Page (in the sample this is the "ImageViewerPage" of the ViewerModule)
This is only working when you do the following navigation:
MainPage -> AttachmentsPage -> ViewerPage -> (back Arrow) AttachmentsPage -> ViewerPage (and so on)
But if you navigate back to MainPage navigation to ViewerPage isn't working anymore:
MainPage -> AttachmentsPage -> ViewerPage -> (back Arrow) AttachmentsPage -> (back Arrow) MainPage -> AttachmentsPage -> (nothing happens anymore when tap on Button to navigate to ViewerPage)
The AttachmentsService gets the NavigationService via Constructor injection and navigates this way:
public AttachmentService(INavigationService navigationService)
{
this.navigationService = navigationService;
}
public async void OpenAttachmentWithViewer(object attachment)
{
// ToDo: handle parameter proberbly
var attachmentType = "image";
// select correct viewer
if (attachmentType == "image")
{
// navigate to image viewer
var navParams = new NavigationParameters();
navParams.Add("object",attachment);
var navTask = this.navigationService.NavigateAsync(
"ImageViewerPage",
navParams,
useModalNavigation: false);
await navTask;
var result = navTask.Status;
Debug.WriteLine($"Navigation State is {result}");
}
}
I tried to check the navigation Task result status, it is always "RanToCompletion".
Modifying the AttachmentsPageViewModel to navigate directly with the Prism NavigationService instead using the Service doesn't cause this behavior:
private void OnOpenAttachment()
{
// ToDo: get the selected attachment
object selectedAttachment = null;
// navigating inside a service -- not working when navigating back to MainPage
//this.attachmentService.OpenAttachmentWithViewer(selectedAttachment);
// navigation from view model -- working
var navParams = new NavigationParameters();
navParams.Add("object", selectedAttachment);
this.navigationService.NavigateAsync("ImageViewerPage", navParams, useModalNavigation: false);
}
Hint: I switched with my Main-Application from PCL-based to the new .NETStandard based solution and already had a similar functionality working successfully using Prism v6.3.0.1. This functionality is not even navigating once since the port.
Actually I don't know how to solve this.
Is it possible to have a look into the Prism NavigationService to determine why the navigation is not happen?
I didn't find any known bug in the Prism Repository yet.