Can I put another ContentPage in ContentPage inside TabbedPage? - xamarin

I have TabbedPage. This has multiple ContentPages inside.
E.g; I have a settings page, I want a new page to be opened by clicking a button in the settings page, hiding the tab part.
When I do as below, the new page is gone, but I have to re-create the TabbedPage to return. Is it possible to create a new page in view with tabbedPage hidden in the background? Can you help if possible?
Application.Current.MainPage = new NavigationPage(new PageTrial());
I'm new to Xamarin sorry if it's a simple rendering.

Original Poster (OP) said Jason's suggestion of Modal page solves their need.

Related

Xamarin Master Detail prism Nav bar back button

I have a masterdetailview that uses prism. When I click on one of the menu items the hamburger menu shows up on the nav bar of the new page I clicked and I really just want the top nav bar to show a back button and be able to go back. How can I achieve this ?
When my app loads I call
await NavigationService.NavigateAsync("/MainPage/NavigationPage");
I figured I could call
await NavigationService.NavigateAsync("/MainPage/NavigationPage/InviteFriends");
and this would provide the newpage with a back button to Home but when I do this it doesn't do anything
EDIT
if I change to
await NavigationService.NavigateAsync("/MainPage/NavigationPage/FeaturePage");
which is what the home page will be called(Feature Page) it will not load the page at all.
MainPage is my list of other pages to go to that is shown when the hamburger is pressed if that helps. Feature page is the page I would want to show below the hamburger page and be the "Home" screen.
am I doing that correctly ?
So if we take your example you have the following Navigation Stack:
MainPage/NavigationPage
Let's assume your navigation code looks like this in the Master-Detail View Model
await NavigationService.NavigateAsync("/MainPage/NavigationPage/InviteFriends");
This will lead to the following Navigation Stack:
/MainPage/NavigationPage/InviteFriends
This is because the navigation was called from the master-detail page.
The master-detail page is considered a root page in Prism and when navigating from a Master-detail page it will set the target page as the detail page of the master-detail.
Check out this article for a more detailed breakdown Link
Be careful - Starting with /MainPage will clear the Navigation stack
One quick solution to this is to add your homepage to the navigation call:
await NavigationService.NavigateAsync("MainPage/NavigationPage/HomePage/InviteFriends");
This will create the following:
MasterDetailPage/NavigationPage/HomePage/InviteFriends
This should hopefully create the response you are looking for.
Hope this helped. Happy coding!
EDIT:
I think if you separate your initial Detail Page out into its own file you should then be able to do the following:
await NavigationService.NavigateAsync("MainPage/NavigationPage/HomePage/InviteFriends");

how to navigate from a content page to the second tab of Tabbed page in xamarin.forms using Prism

once user click on the search bar he/she directs to a model content page and after searching and selecting the search result. I want user to redirect to the second tab of a tabbed page.
is this possible using prism ?
Navigation for TabbedPages has been improved with Prism 7. Please see the blog post here
NavigateAsync(“TabbedPage?selectedTab=MiddleTab/ViewA/ViewB”)
This will navigate to the TabbedPage, selected the MiddleTab and continue navigating ViewA and ViewB onto the navigation stack.
The blog post ist not 100% clear, but don't take MiddleTab literally. Most likely this will be the class name of a view added to the TabbedPage.

How to show Menu in MasterDetail Page when using Prism and Custom Title bar

I am completely new to Xamarin.
I am working on a project where Prism framework is used for navigation (my first xamarin project) The requirement needed a custom title bar. I have implemented it as detailed out in this tutorial
https://wolfprogrammer.com/2016/07/07/custom-app-header-in-forms/
Now with prism navigation, how to show the masterdetail page menu i.e. set the IsPresented property of MasterPage to true when the user clicks the custom hamburger icon.
I have been reading about this for hours now and not able to understand any of the solutions mentioned nor are they working for me? Could someone please break it down for a complete beginner here?
Some links that I have referred so far
https://forums.xamarin.com/discussion/93409/prism-how-show-hide-programmatically-the-masterdetailpage-menu
https://github.com/PrismLibrary/Prism/issues/570
Just have a boolean property in your Master page's ViewModel, let's call it IsMenuPresented, then in your MasterPage XAML:
<MasterDetailPage
x:Class="YourProject.Views.MasterPage"
...
MasterBehavior="Popover"
IsPresented="{Binding IsMenuPresented, Mode=TwoWay}">
If you want to be able to toggle the menu from code, you can either:
1) do something like
(App.Current.MainPage is MasterDetailPage mainPage).IsPresented = true;
2) Use Prism's Event Aggregator to subscribe to an event in the Master Page's ViewModel that will listen for a true/false value that gets published from some other ViewModel and set IsMenuPresented accordingly (thereby showing/hiding the menu).

Xamarin Form: MasterDetailPage: Does the detail page have to be NavigationPage as a standard

In the sample code from Xamarin website, the Detail page was added to a NavigationPage
Detail = new NavigationPage(new TestPage());
Does TestPage have to be wrapped by NavigationPage? If I remove NavigationPage and just put new TestPage(), it will work on me. If I keep NavigationPage in, I have the error which I have posted in here.
Reference from my other post
If without NavigationPage, the hamburger icon will be gone, even though still able to show the master page.
From official Xamarin documentation:
Public Constructors
NavigationPage()
Initializes a new NavigationPage object.
NavigationPage(Page)
Creates a new NavigationPage element with root as its root element.
So you only need/want/have to pass a page as argument if you want to specify that it's a root element.
Also in case you developing an UWP app with MasterDetailPage you should keep in mind:
Generally, you'll set these two properties to objects of type
ContentPage, but currently, to get MasterDetailPage to work on the
Universal Windows Platform, the detail page must be a NavigationPage.

MVVM Cross ShowViewModel doesn't work on UWP with custom

I refer from this StackOverflow question, regarding to MVVM Light:
I am trying to have a hamburger menu style navigation (see this
sample). app by Microsoft on an example of how to do this) to:
1- have a convenient solution shared across all my pages. The sample
mentioned above uses an AppShell Page as the root of the app instead
of a Frame, that encapsulates the navigation menu and some behavior of
the back button. That would be ideal.
2- Use the MVVM-Light navigation service to handle all the navigation
from my view model conveniently.
Here is how the App.xml.Cs initializes the shell page onLaunched:
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
var shell = Window.Current.Content as AppShell;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (shell == null)
{
// Create a AppShell to act as the navigation context and navigate to the first page
shell = new AppShell();
// Set the default language
shell.Language = ApplicationLanguages.Languages[0];
shell.AppFrame.NavigationFailed += OnNavigationFailed;
}
// Place our app shell in the current Window
Window.Current.Content = shell;
if (shell.AppFrame.Content == null)
{
// When the navigation stack isn't restored, navigate to the first page
// suppressing the initial entrance animation.
var setup = new Setup(shell.AppFrame);
setup.Initialize();
var start = Mvx.Resolve<IMvxAppStart>();
start.Start();
}
// Ensure the current window is active
Window.Current.Activate();
}
The thing is, as long as i navigate over the menu proviced by the AppShell everything works. But the ShowViewModel from MVVM Cross doesn't have any effect.
I thought there shouldn't be any difference if pass the shell as Frame or the frame set on the AppShell.
Does anyone have an idea what I can do about this or if there is an example with a working hamburger menu with MVVM cross?
The repository is open source on GitHub if you need an better overview or so.
https://github.com/Apply-Solutions/MoneyManager
I use MVVM Cross v4.0.0.0-beta1. Beta2 has currently another issue who prevents building in a UWP.
Thanks
NPadrutt
Not entirely sure what you are trying to do, but what you will probably need to navigate pages with a hamburger menu in a UWP app using MvvmCross as a framework, is a custom presenter, which handles the ShowViewModel method, and displays the associated view for the requested ViewModel in your hamburger container view.
Okey this embarrassing. The issue was that the View for the ViewModel couldn't be resolved. And the reason for that was that I didn't replace the inheritance from page to views:MvxWindowsPage.
With this, everything works with the default page presenter.
EDIT: in order to work with the navigation in the app shell, these pages need to be Pages. So you may either have to rewrite the navigation in the Appshell or may not adjust all Pages to MvxPage.

Resources