TitleBar.IsBackButtonEnabled プロパティ

定義

戻るボタンが有効かどうかを示す値を取得または設定します。

public:
 property bool IsBackButtonEnabled { bool get(); void set(bool value); };
/// [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")]
/// [get: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")]
/// [set: Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")]
bool IsBackButtonEnabled();

void IsBackButtonEnabled(bool value);
public bool IsBackButtonEnabled { [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")] get; [Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValue(value="true")] set; }
[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

プロパティ値

Boolean

bool

true 戻るボタンが有効になっている場合。それ以外の場合は false。 既定値は true です。

属性
Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValueAttribute

<!-- 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();
    }
}

注釈

通常、IsBackButtonEnabled プロパティは、戻るナビゲーションを実行する FrameCanGoBack プロパティにバインドする必要があります。 これにより、戻るナビゲーションが不可能な場合は戻るボタンが自動的に無効になり、可能な場合はボタンが有効になります。

NavigationView コントロールで TitleBar コントロールを使用する場合は、ナビゲーション ビューの戻るボタンをタイトル バーの戻るボタンに置き換える必要があります。

以下のことをお勧めします。

  • NavigationView コントロールの [戻る] ボタンを非表示にします。 <NavigationView IsBackButtonVisible="Collapsed">
  • TitleBar コントロールの [戻る] ボタンを表示します。 <TitleBar IsBackButtonVisible="True">
  • TitleBar.BackRequested イベントを処理して戻ります。

適用対象

こちらもご覧ください

  • BackRequested
  • <xref:Microsoft.UI.Xaml.Controls.TitleBar.IsBackButtonVisible+%5bNavigationView.IsBackButtonVisible%5d(%2fwindows%2fwindows-app-sdk%2fapi%2fwinrt%2fmicrosoft.ui.xaml.controls.navigationview.isbackbuttonvisible)>