处理 Windows 10 Mobile 上的底部导航栏

Handling bottom navigation bar on Windows 10 Mobile

在我的 Xamarin.Forms 应用程序中,底部有一个按钮。此按钮隐藏在 Windows 10 Mobile phone 上。是否没有设置让我的页面大小适应可用大小?在这种情况下,如果显示导航栏,我的页面高度会降低,如果隐藏导航栏,它会增加。

我看到建议以编程方式隐藏导航栏的解决方案。例如

ApplicationView.GetForCurrentView().TryEnterFullScreenMode();

应该放在哪里?我把它放在 OnLaunchedrootFrame.Navigate 之前的 App.xaml.cs 中。如果我 运行 我本地机器上的应用程序变成了全屏。移动端phone导航栏被隐藏,但底部留有白色区域。

而且我试过了

ApplicationView.GetForCurrentView().FullScreenSystemOverlayMode = FullScreenSystemOverlayMode.Minimal;

但我看不出有什么不同。

开发人员应该如何处理导航栏而不隐藏其下方的内容?

这似乎解决了问题:

ApplicationView.GetForCurrentView().SuppressSystemOverlays = true;

结果是启动应用程序时不显示导航栏。用户可以通过向上滑动来显示导航栏。此处页面会根据需要自动调整大小。

我把它放在App.xaml.cs中的OnLaunched方法中:

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;

    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == null)
    {
        // Create a Frame to act as the navigation context and navigate to the first page
        rootFrame = new Frame();

        rootFrame.NavigationFailed += OnNavigationFailed;

        Xamarin.Forms.Forms.Init(e);

        if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            //TODO: Load state from previously suspended application
        }

        // Place the frame in the current Window
        Window.Current.Content = rootFrame;
    }

    if (rootFrame.Content == null)
    {
        // When the navigation stack isn't restored navigate to the first page,
        // configuring the new page by passing required information as a navigation
        // parameter
        ApplicationView.GetForCurrentView().SuppressSystemOverlays = true;
        rootFrame.Navigate(typeof(MainPage), e.Arguments);
    }
    // Ensure the current window is active
    Window.Current.Activate();
}

您还可以使用:

ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);

在 onLauched 函数的 UWP App.xaml.cs 文件中,如下所示:

protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        if (System.Diagnostics.Debugger.IsAttached)
        {
            this.DebugSettings.EnableFrameRateCounter = true;
        }

        Frame rootFrame = Window.Current.Content as Frame;

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (rootFrame == null)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();

            rootFrame.NavigationFailed += OnNavigationFailed;

            Xamarin.Forms.Forms.Init(e);

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            // Place the frame in the current Window
            Window.Current.Content = rootFrame;
        }

        if (rootFrame.Content == null)
        {
            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
            rootFrame.Navigate(typeof(MainPage), e.Arguments);
        }
        // Ensure the current window is active
        Window.Current.Activate();
    }

这将确保您的应用位于可见区域内,从而不会覆盖底部导航栏。