UWP - Hide the title bar programmatically
The following Universal Windows Platform application development
tutorial demonstrates how we can hide the title bar programmatically. Here we
will get the application view for the current view. Then we will get the title
bar of the application view. After getting the title bar we will set the title
bar background color to transparent color. We also extend the core application
view into the title bar. As a result, the title bar will be hidden.
The ApplicationView class represents the active application view and associated states and behaviors. The ApplicationView class GetForCurrentView() method gets the view state and behavior settings of the active application. This method returns an ApplicationView instance that can be used to get and set app display properties.
The ApplicationView class TitleBar property gets the title bar of the app. This property value is an ApplicationViewTitleBar which is the title bar of the app.
The ApplicationViewTitleBar class represents the title bar of an app. The ApplicationViewTitleBar BackgroundColor property gets or sets the color of the title bar background. Here we will set this title bar background color to a transparent color that will technically hide the title bar.
The CoreApplication class enables apps to handle state changes, manage windows, and integrate with a variety of UI frameworks. The CoreApplication GetCurrentView() method gets the view corresponding to the current thread.
The CoreApplicationView class represents an app window and its thread. The CoreApplicationView TitleBar property gets the title bar associated with the current view. This property value is a CoreApplicationViewTitleBar which is the title bar associated with the current view.
The CoreApplicationViewTitleBar class enables an app to define a custom title bar that displays in the app's window.
The CoreApplicationViewTitleBar ExtendViewIntoTitleBar property gets or sets a value that specifies whether this title bar should replace the default window title bar. This property value is a Boolean. The UWP developers can set this property value to true to replace the default window title bar. So here we will set this property value to true. Finally, the title bar will be hidden.
The ApplicationView class represents the active application view and associated states and behaviors. The ApplicationView class GetForCurrentView() method gets the view state and behavior settings of the active application. This method returns an ApplicationView instance that can be used to get and set app display properties.
The ApplicationView class TitleBar property gets the title bar of the app. This property value is an ApplicationViewTitleBar which is the title bar of the app.
The ApplicationViewTitleBar class represents the title bar of an app. The ApplicationViewTitleBar BackgroundColor property gets or sets the color of the title bar background. Here we will set this title bar background color to a transparent color that will technically hide the title bar.
The CoreApplication class enables apps to handle state changes, manage windows, and integrate with a variety of UI frameworks. The CoreApplication GetCurrentView() method gets the view corresponding to the current thread.
The CoreApplicationView class represents an app window and its thread. The CoreApplicationView TitleBar property gets the title bar associated with the current view. This property value is a CoreApplicationViewTitleBar which is the title bar associated with the current view.
The CoreApplicationViewTitleBar class enables an app to define a custom title bar that displays in the app's window.
The CoreApplicationViewTitleBar ExtendViewIntoTitleBar property gets or sets a value that specifies whether this title bar should replace the default window title bar. This property value is a Boolean. The UWP developers can set this property value to true to replace the default window title bar. So here we will set this property value to true. Finally, the title bar will be hidden.
MainPage.xaml
<Page
x:Class="UniversalAppTutorials.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniversalAppTutorials"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
>
<StackPanel Background="PaleGoldenrod" Padding="50">
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using Windows.UI.ViewManagement;
using Windows.UI;
using Windows.ApplicationModel.Core;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// Get the application view title bar
ApplicationViewTitleBar appTitleBar = ApplicationView.GetForCurrentView().TitleBar;
// Make the title bar transparent
appTitleBar.BackgroundColor = Colors.Transparent;
// Get the core appication view title bar
CoreApplicationViewTitleBar coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
/*
ExtendViewIntoTitleBar
Gets or sets a value that specifies whether this title
bar should replace the default window title bar.
*/
// Extend the core application view into title bar
coreTitleBar.ExtendViewIntoTitleBar = true;
}
}
}