在横向模式下隐藏ToolBar Xamarin.Forms

问题描述 投票:1回答:1

我有一个MasterPage,我想在横向模式中隐藏ToolBar,但是能够与MasterDetailPage进行交互。我在Google日历中看到了这个:enter image description here

enter image description here

xamarin.forms xamarin.android
1个回答
1
投票

实现设备定位逻辑(使用插件,例如:https://github.com/aliozgur/Xamarin.Plugins/tree/master/DeviceOrientation或自己使用依赖服务实现),然后:

protected override void OnAppearing()
{
    base.OnAppearing();

    _RotatePage();

    SizeChanged += _SizeChanged;
}

protected override void OnDisappearing()
{
    SizeChanged -= _SizeChanged;

    base.OnDisappearing();
}

private void _SizeChanged(object sender, EventArgs e)
{
    var svc = DependencyService.Get<IDeviceOrientationService>();
    var orientation = svc.GetOrientation();

    NavigationPage.SetHasNavigationBar(this, orientation == DeviceOrientation.Portrait);
}
© www.soinside.com 2019 - 2024. All rights reserved.