46

I want to hide the navigation bar in a page created using WPF. I have tried ShowsNavigationUI = false, but it is still displaying the control.

10 Answers 10

107

Specify to the page Container, the intention to not have a navigation bar, using NavigationUIVisibility property.

<Frame NavigationUIVisibility="Hidden" Panel.ZIndex="1" ... />
1
  • Simple and straightforward. To me, the best answer to this question. Also if you want to see the page navigation system always instead of hiding it. In that case NavigationUIVisibility="Visible" will do the trick.
    – GeertVc
    Commented Feb 7, 2021 at 16:01
41

It's a very easy implementation.

<Frame x:Name="_FrameName" NavigationUIVisibility="Hidden" />
25

Setting ShowsNavigationUI=False on a Page ought to do it. There does seem to be a bug, however, that will cause this to fail in at least one sequence of events:

  1. Page is already in NavigationWindow when this is set
  2. Page is navigated away and back again

There may be other scenarios I haven't run into yet that make it fail.

To get this to work totally reliably, what I do is ignore the Page.ShowsNavigationUI property entirely and set it instead on NavigationWindow. This seems to be completely reliable.

Here is how this can be done in your Page constructor:

Dispatcher.BeginInvoke(ApplicationPriority.Render, new Action(() =>
{
  var navWindow = Window.GetWindow(this) as NavigationWindow;
  if(navWindow!=null) navWindow.ShowsNavigationUI = false;
}));

If you do this, remember not to set ShowsNavigationUI on any Page object.

FYI, you can also restyle your NavigationWindow any way you like by changing its ControlTemplate. For example this removes everything but the actual page content:

  <Style TargetType="{x:Type NavigationWindow}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type NavigationWindow}">

          <AdornerDecorator>
            <ContentPresenter Name="PART_NavWinCP" 
                              ClipToBounds="true"/>
          </AdornerDecorator>
          
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
3
  • I cannot find ApplicationPriority. What class is is it in? I have this same problem but for me it is random.
    – paparazzo
    Commented Oct 13, 2011 at 16:16
  • Change the 'ApplicationPriority.Render' by 'DispatcherPriority.Loaded'
    – Farmer
    Commented Mar 14, 2014 at 13:36
  • 2
    Below answers are far easier, Just do NavigationUIVisibility="Hidden" on the frame element Commented Jun 21, 2018 at 22:18
9

If you're using a Frame you can change the Frame's default style to remove the navigation buttons (shown below). The same approach could be done for NavigationWindow. I originally tried setting Page.ShowsNavigationUI and it had no effect. Just add the below style to a ResourceDictionary and it works fine.

<Style TargetType="{x:Type Frame}">
  <Setter Property="Control.Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type Frame}">
        <Border BorderThickness="{TemplateBinding Border.BorderThickness}" Padding="{TemplateBinding Control.Padding}" BorderBrush="{TemplateBinding Border.BorderBrush}" Background="{TemplateBinding Panel.Background}">
          <ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" Name="PART_FrameCP" />
        </Border>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>
7

This one I found really easy. In your MainWindow, do this:

public MainWindow()
   public partial class MainWindow : NavigationWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            ShowsNavigationUI = false;
        }
    }
}

And if you have an event on button click to open a new page, just do this:

private void btnEndUserSearch_Click(object sender, RoutedEventArgs e)
{
            EndUser EndUserSearchPage = new EndUser();
            this.NavigationService.Navigate(EndUserSearchPage);
            EndUserSearchPage.ShowsNavigationUI = false;
}
0
3

Above works only for Navigation windows, but I am using ordinary WPF windows. Some say these are better than Navigation windows. I am using DockPanel to host my pages. My solution creates a new template for the DockPanel and simply does not add buttons or makes them hidden (see StackPanel Visibility="Hidden"). It works nicely.

<DockPanel>    
    <Frame x:Name="_mainFrame">
    <Frame.Template>

        <ControlTemplate TargetType="Frame">
            <DockPanel Margin="7">
                <StackPanel Visibility="Hidden"
                    Margin="0"
                    Orientation="Horizontal"
                    DockPanel.Dock="Top"
                    >
                    <!--<Button
                        Content="Avast! Go back!" 
                        Command="{x:Static NavigationCommands.BrowseBack}" 
                        IsEnabled="{TemplateBinding CanGoBack}" 
                        />
                    <Button 
                        Content="Forward you dogs!" 
                        Command="{x:Static NavigationCommands.BrowseForward}" 
                        IsEnabled="{TemplateBinding CanGoForward}" 
                        />-->
                </StackPanel>

               <Border>
                    <ContentPresenter />
               </Border>
            </DockPanel>
        </ControlTemplate>

        </Frame.Template>
    </Frame>
</DockPanel>
1
  • does this permit you to dynamically load and close pages, while keeping your main page open? Commented Jul 18, 2016 at 16:49
1

One of the easiest and simplest way is to add: ShowsNavigationUI = false; in your cs file constructor under InitializeComponent();

1

For beginners, you can simply change code at MainWindow.xaml like this.

    <Window>
       <Grid >
          <Frame x:Name="LeftFrame" NavigationUIVisibility="Hidden"/>
          <Frame x:Name="RightFrame" NavigationUIVisibility="Hidden"/>
       </Grid>
    </Window>
0

I had this problem whenever I dynamically changed the Content property of a Frame, and solved it by using the following code in my click() event.

ContentFrame.NavigationUIVisibility = NavigationUIVisibility.Hidden;

Where ContentFrame is the name of the frame, as defined in XAML. i.e.

<Frame x:Name="ContentFrame"  />
0

On the NavigationWindow itself I use ShowsNavigationUI="False"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.