Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

xamarin forms PrefersHomeIndicatorAutoHidden set to true on pages not working upon navigation

mikee0423mikee0423 Member ✭✭
edited October 23 in Xamarin.Forms

I have set

ios:Page.PrefersHomeIndicatorAutoHidden="true"

on all my content page but home indicator is not hidden upon navigating to other page. It only works on the first load of the first page. Also tried it in code behind using,

On().SetPrefersHomeIndicatorAutoHidden(true);

Same behavior, it doesn't work upon navigating to other page.

Anyone have the same experience?

Tagged:

Best Answer

  • mikee0423mikee0423 Member ✭✭
    Accepted Answer

    Got it working by using Absolute Navigation in Prism Navigation.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Try to create a base page like:

    public class BasePage : ContentPage
    {
        public BasePage()
        {
            On<iOS>().SetPrefersHomeIndicatorAutoHidden(true);
        }
    }
    

    And then make each page inherit from this page like:

    <local:BasePage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="ScreenSample.MainPage"
                 xmlns:local="clr-namespace:ScreenSample">
    
        <StackLayout>
    
            <Button Text="Click" Clicked="Button_Clicked"/>
        </StackLayout>
    
    </local:BasePage>
    

    Code-behind:

    public partial class MainPage : BasePage
    {
        public MainPage()
        {
            InitializeComponent();
        }
    
        private void Button_Clicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new SecondPage());
        }
    }
    
  • mikee0423mikee0423 Member ✭✭

    @LandLu Tried you suggestion on creating a base page and inheriting it on my pages but still the same behavior, Home Indicator is not being hidden on the next page. I'm using prism navigation btw

        public class CustomContentPage : ContentPage
        {
            public CustomContentPage()
            {
                On<iOS>().SetPrefersHomeIndicatorAutoHidden(true);
            }
        }
    
    <controls:CustomContentPage
        x:Class="InVentryPassport.Views.MainPage"
        xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:behavior="clr-namespace:InVentryPassport.Behaviors;assembly=InVentryPassport"
        xmlns:controls="clr-namespace:InVentryPassport.Controls"
        xmlns:converters="clr-namespace:InVentryPassport.Converters"
        xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms"
        xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
        prism:ViewModelLocator.AutowireViewModel="True"
        NavigationPage.HasNavigationBar="false">
    
        public partial class MainPage : CustomContentPage
        {
            public MainPage()
            {
                InitializeComponent();
            }
       }
    
  • mikee0423mikee0423 Member ✭✭

    It's working without using Prism Navigation so the issue is with Prism Navigation. Haven't found a solution yet with Prism.

  • mikee0423mikee0423 Member ✭✭
    Accepted Answer

    Got it working by using Absolute Navigation in Prism Navigation.

  • LandLuLandLu Member, Xamarin Team Xamurai

    Glad you made it.
    Could you please mark the answer to end the conversation?

Sign In or Register to comment.