TitleBar.IsBackButtonEnabled Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets a value that indicates whether the button to navigate back is enabled.
public:
property bool IsBackButtonEnabled { bool get(); void set(bool value); };
/// [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")]
/// [get: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")]
/// [set: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")]
bool IsBackButtonEnabled();
void IsBackButtonEnabled(bool value);
[Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")]
public bool IsBackButtonEnabled { [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")] get; [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")] set; }
var boolean = titleBar.isBackButtonEnabled;
titleBar.isBackButtonEnabled = boolean;
Public Property IsBackButtonEnabled As Boolean
Property Value
bool
true
if the button to navigate back is enabled; otherwise, false
. The default is true
.
- Attributes
-
Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValueAttribute
Examples
<!-- MainWindow.xaml -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TitleBar Title="My App"
IsBackButtonVisible="True"
IsBackButtonEnabled="{x:Bind RootFrame.CanGoBack, Mode=OneWay}"
BackRequested="TitleBar_BackRequested">
</TitleBar>
<NavigationView x:Name="RootNavigationView" Grid.Row="1"
IsBackButtonVisible="Collapsed">
<Frame x:Name="RootFrame" />
</NavigationView>
</Grid>
// MainWindow.xaml.cs
private void TitleBar_BackRequested(TitleBar sender, object args)
{
if (RootFrame.CanGoBack)
{
RootFrame.GoBack();
}
}
Remarks
Typically, you should bind the IsBackButtonEnabled
property to the CanGoBack property of the Frame that will perform the back navigation. This will automatically disable the back button when back navigation is not possible and enable the button when it is possible.
When you use the TitleBar control with a NavigationView control, you should replace the navigation view's back button with the title bar's back button.
We recommend that you:
- Hide the back button in the
NavigationView
control.<NavigationView IsBackButtonVisible="Collapsed">
- Show the back button in the
TitleBar
control.<TitleBar IsBackButtonVisible="True">
- Handle the TitleBar.BackRequested event to navigate back.
Applies to
See also
- BackRequested
- <xref:Microsoft.UI.Xaml.Controls.TitleBar.IsBackButtonVisible+%5bNavigationView.IsBackButtonVisible%5d(%2fwindows%2fwindows-app-sdk%2fapi%2fwinrt%2fmicrosoft.ui.xaml.controls.navigationview.isbackbuttonvisible)>