TitleBar.BackRequested Event
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.
Occurs when the back navigation button is invoked.
// Register
event_token BackRequested(TypedEventHandler<TitleBar, IInspectable const&> const& handler) const;
// Revoke with event_token
void BackRequested(event_token const* cookie) const;
// Revoke with event_revoker
TitleBar::BackRequested_revoker BackRequested(auto_revoke_t, TypedEventHandler<TitleBar, IInspectable const&> const& handler) const;
public event TypedEventHandler<TitleBar,object> BackRequested;
function onBackRequested(eventArgs) { /* Your code */ }
titleBar.addEventListener("backrequested", onBackRequested);
titleBar.removeEventListener("backrequested", onBackRequested);
- or -
titleBar.onbackrequested = onBackRequested;
Public Custom Event BackRequested As TypedEventHandler(Of TitleBar, Object)
Event Type
TypedEventHandler<TitleBar,IInspectable>
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
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 this event to navigate back.
Applies to
See also
- IsBackButtonVisible
- <xref:Microsoft.UI.Xaml.Controls.TitleBar.IsBackButtonEnabled+%5bNavigationView.IsBackButtonVisible%5d(%2fwindows%2fwindows-app-sdk%2fapi%2fwinrt%2fmicrosoft.ui.xaml.controls.navigationview.isbackbuttonvisible)>