How to remove huge title bar from Xamarin.Forms WPF application?

Viewed 164

I've got a Xamarin.Forms WPF application running, but there is a huge title bar.

enter image description here

I have tried the solution of adding NavigationPage.SetHasNavigationBar(this, false); inside my MainPage class's constructor

Here is the code:

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
        NavigationPage.SetHasNavigationBar(this, false);
    }
}

Still I am getting huge title bar size in WPF application, on the other hand, while running on UWP, it is working fine.

1 Answers

You could try to add below codes in your MainWindow.xaml.cs in wpf project:

protected override void OnActivated(EventArgs e)
    {
        base.OnActivated(e);
        if (!topBarsRemoved) RemoveTopBars();
    }
private bool topBarsRemoved = false;

private void RemoveTopBars()
    {
        var topAppBar = this.Template.FindName("PART_TopAppBar", this) as FormsAppBar;
        if (topAppBar != null)
            (topAppBar.Parent as System.Windows.Controls.Grid)?.Children.Remove(topAppBar);
        topBarsRemoved = true;
    }
Related