When I use INavigationService to navigate from my first page to other page, the BackButton in uwp( on desktop) supposed to be visible and become invisible when I navigate back.
Now I have to set AppViewBackButtonVisibility to be visible at first. And I cannot set it to be invisible appropriately because there is no navigation related event happened and no CanGoBack I can use.
This is happened in prism for Xamarin Forms project.
BTW, could we have a same INavigationService definition in prism for Xamarin and prism for windows10. Now in preview version we use NavigateAsync for Xamarin etc. and also there is no CanGoBack there. In this way I cannot share my ViewModels convenient in share project between xamarin forms and uwp when I want use totally pure uwp things without Xamarin Forms. If we can abstract the INavigationService from prism for xamarin forms and uwp to a common place, it would be more convenient. Because then I do not have to use different using in the share project for different platforms.
Thanks:)
I'm confused. What platform are you talking about UWP or Xamarin.Forms? Could you please clarify your issue?
Currently, we can't have the same INavigationService definition in UWP and Xamarin.Forms. You can see how vastly different the navigation paradigms are between the two platforms. Also, there is no CanGoBack equivalent in Xamarin.Forms. How would you expect CanGoBack to work for in Xamarin.Forms? What would CanGoback actually do to determine if it can go back or not?
I was talking about Xamarin.Forms for UWP and with prism. The back button should be automatically be visible or invisible when I running my Xamarin.Forms for UWP app on windows10 desktop but it`s not working.
For the CanGoBack in Xamarin.Forms,
I registered an event in eventaggregator, and each time I was trying to Navigate I will publish this event. When I get this event I will check CanGoBack and set AppViewBackButtonVisibility.
I'm sorry, but you still have not provided enough information for me to understand exactly what you are asking for.
To automatically get the back button in Xamarin.Forms, you must be within a NavigationPage.
Hi Brian,
I think I also encounter this problem (missing Back button) and I'll try to explain it more precisely.
Compare two cases:
sealed partial class App : PrismUnityApplication
{
public App()
{
InitializeComponent();
}
protected override async Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
NavigationService.Navigate("Main", null);
}
}
public class MainPageViewModel : BindableBase
{
protected INavigationService navigationService;
public MainPageViewModel(INavigationService navigationService)
{
this.navigationService = navigationService;
GoToView2Command = new DelegateCommand(GoToView2);
}
public DelegateCommand GoToView2Command { get; private set; }
private void GoToView2()
{
navigationService.Navigate("View2", null);
}
}
All works as expected - when I go to View2 there is Back button shown on application title bar.
public partial class App : PrismApplication
{
protected override async void OnInitialized()
{
InitializeComponent();
await NavigationService.NavigateAsync("MainPage?title=Hello%20from%20Xamarin.Forms");
}
protected override void RegisterTypes()
{
Container.RegisterTypeForNavigation<MainPage>();
Container.RegisterTypeForNavigation<XFNavigationPage>();
Container.RegisterTypeForNavigation<View2Page>();
}
}
public class MainPageViewModel : BindableBase, INavigationAware
{
private string _title;
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
protected INavigationService navigationService;
public MainPageViewModel(INavigationService navigationService)
{
this.navigationService = navigationService;
GoToView2Command = new DelegateCommand(GoToView2);
}
public void OnNavigatedFrom(NavigationParameters parameters)
{
}
public void OnNavigatedTo(NavigationParameters parameters)
{
if (parameters.ContainsKey("title"))
Title = (string)parameters["title"] + " and Prism";
}
public DelegateCommand GoToView2Command { get; private set; }
private async void GoToView2()
{
await navigationService.NavigateAsync("XFNavigationPage/View2Page");
}
}
The bug - when I go to View2 there IS NO Back button shown on application title bar.
Can you reproduce this?
Plamen
This is because you are navigating from MainPage to a NavigationPage with only one Page on it's stack, hence no back button. If you want a back button to show when navigating to View2page, then you must wrap the MainPage in a navigationPage.
NavigationService.NavigateAsync("MyNavPage/MainPage?title=Hello%20from%20Xamarin.Forms");
Tried this - still no back button.
Make sure in your MainPageViewModel you navigate without having the NavPage in the uri.
NavigateAsync("View2Page");
otherwise you are navigating to a different navigation page instance with only one view on its stack.
OK, this works - thanks :-)
Hope these clarifications also help others.
@brianlagunas Hi, I am navigating form App.xaml.cs
NavigateAsync("NavigationPage/MainTabPage/TabPage1");
And from TabPage1 I'm navigating to
NavigateAsync("TestPage");
But still I am not getting back button. And if I try
NavigateAsync("NavigationPage/MainTabPage/TabPage1/TestPage");
Back Button is showing.
Am I missing something?
@KalpeshChheda you need to specify that you don't want to use modal navigation. Set the useModalNavigation parameter to false.
Thanks Brian. But still something is not working.
How can i navigate from TabbedPages(ChildTabPage1, ChildTabPage2, ChildTabPage3) to ContentPage With Back Button
eg.
From App.xaml.cs to <TabbedPage>
And from TabPage Children to
<ChildTabPage1>
<ChildTabPage2> here --> <ContentPage> with back button to --> <TabbedPage> again
<ChildTabPage3>
Can you provide a sample app that reproduces the issue?
Ya sure, Below is the link
https://github.com/KalpeshChheda/PrismTestApp
When i am navigating SettingPage from tabbedpage (SimpleTabbedPage) or from MasterDetailPage(MainPage) back-button is not showing.
I want to keep useModalNavigation to true because i don't want to see tabs when i am on SettingPage.
I want to keep useModalNavigation to true because i don't want to see tabs when i am on SettingPage.
If you want modal navigation, you will never have a back button. Only navigation that occurs within a NavigationPage will have a back button (non-modal navigation).
In any other way is it possible? If no I will manually create back button.
Prism is awesome library. Thanks.
I took a look at the sample app, first of all stop using the DelegateCommand.FromAsyncHandler. It is going to be removed in the next release, and provides no benefit.
Regarding naivating to SettingsPage from MainPage (MasterDetail). Currently when you navigate it is being set as the Detail of the MainPage, but it is not wrapped in a NavigationPage so there is no hamburger menu at the top. This is why hitting hardware back button closes app, because the MainPage is still the root page. If you want the hambuger menu you need to navigate to the SettingPage and wrap it in a NavigationPage like NavigateAsync("NavPage/SettingsPage"). If you don't want the SettingsPage to be set as the detail when you navigate, you need to navigate to it modally (useModalNavigation=true).
Like I said, the only way to get a back button is to have your page wrapped in a NavigationPage. So no, unless you wrap your pages in navigation pages you won't get a back button. You'll have to add one manually with a custom renderer.
Ok. thanks for looking sample app. Actually WhatsApp is having same kind of navigation so wanted to give a try. Thanks again I learn a lot from you.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.