TitleBar.BackRequested Événement
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Se produit lorsque le bouton de navigation arrière est appelé.
// 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)
Type d’événement
TypedEventHandler<TitleBar,IInspectable>
Exemples
<!-- 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();
}
}
Remarques
Lorsque vous utilisez le contrôle TitleBar avec un contrôle NavigationView , vous devez remplacer le bouton Précédent de la vue de navigation par le bouton Précédent de la barre de titre.
Nous vous recommandons de :
- Masquez le bouton Précédent dans le
NavigationViewcontrôle.<NavigationView IsBackButtonVisible="Collapsed"> - Afficher le bouton Précédent dans le
TitleBarcontrôle.<TitleBar IsBackButtonVisible="True"> - Gérez cet événement pour revenir en arrière.
S’applique à
Voir aussi
- IsBackButtonVisible
- <xref:Microsoft.UI.Xaml.Controls.TitleBar.IsBackButtonEnabled+%5bNavigationView.IsBackButtonVisible%5d(%2fwindows%2fwindows-app-sdk%2fapi%2fwinrt%2fmicrosoft.ui.xaml.controls.navigationview.isbackbuttonvisible)>