TitleBar.BackRequested 活动
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
调用后退导航按钮时发生。
// 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)
事件类型
TypedEventHandler<TitleBar,IInspectable>
示例
<!-- 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();
}
}
注解
将 TitleBar 控件与 NavigationView 控件结合使用时,应将导航视图的后退按钮替换为标题栏的后退按钮。
我们建议您:
- 隐藏控件中的
NavigationView后退按钮。<NavigationView IsBackButtonVisible="Collapsed"> - 在控件中
TitleBar显示后退按钮。<TitleBar IsBackButtonVisible="True"> - 处理此事件以导航回去。
适用于
另请参阅
- IsBackButtonVisible
- <xref:Microsoft.UI.Xaml.Controls.TitleBar.IsBackButtonEnabled+%5bNavigationView.IsBackButtonVisible%5d(%2fwindows%2fwindows-app-sdk%2fapi%2fwinrt%2fmicrosoft.ui.xaml.controls.navigationview.isbackbuttonvisible)>