Forum General

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to navigate to a different content page after a function is called

ikreieikreie Member ✭✭

I have an app that has 2 tabs in Xamarin forms (iOS side). I'd like to know how to make my app navigate to a different content page after a function is called. Let me show you what I mean in code:

these are my two functions in my content page:

 protected override async void OnAppearing()
        {
            base.OnAppearing();
            TakePhotoButton_Clicked();
        }

        async void TakePhotoButton_Clicked()
        {
            if (App.pictureTaken) return;
            App.pictureTaken = true;

            //Allows users to take pictures in the app
            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                DisplayAlert("No Camera", "Camera is not available.", "OK");
                return;
            }

            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                //Sets the properties of the photo file 
                SaveToAlbum = true,
                PhotoSize = PhotoSize.MaxWidthHeight,
                DefaultCamera = CameraDevice.Rear
            });

            if (file == null)
                return;
        }

After calling the TakePhotoButton_Clicked() I'd like to force my app to navigate to my other content page.

in pseudocode it would look like:

NavigateTo(MyOtherContentPage);

But im not sure how that would work or if something like that exists. Any suggestions?

Best Answer

Answers

  • ikreieikreie Member ✭✭

    @kingwisdoms this takes me to a new page but i also want the tabs to show up at the bottom as well. how do i do that?

  • kingwisdomskingwisdoms Member ✭✭

    Application.Current.MainPage = new NavigationPage(new MyTabbedPage());

    on your TabbedPage .xaml.cs file
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MyTabbedPage : TabbedPage
    {
    public MyTabbedPage()
    {
    InitializeComponent();

            NavigationPage ChurchVisited = new NavigationPage(new ChurchVisited());
    
            ChurchVisited.Title = "ChurchVisited";
    
    
            Children.Add(new Dashboard());
            Children.Add(new ChurchVisited());
    
    
        }
    }
    
Sign In or Register to comment.