TitleBar.IsBackButtonEnabled Proprietà

Definizione

Ottiene o imposta un valore che indica se il pulsante per spostarsi indietro è abilitato.

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

Valore della proprietà

Boolean

bool

true se il pulsante per spostarsi indietro è abilitato; in caso contrario, false. Il valore predefinito è true.

Attributi
Microsoft.UI.Xaml.CustomAttributes.MUXPropertyDefaultValueAttribute

Esempio

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

Commenti

In genere, è necessario associare la IsBackButtonEnabled proprietà alla proprietà CanGoBack di Frame che eseguirà lo spostamento indietro. In questo modo si disabilita automaticamente il pulsante Indietro quando lo spostamento indietro non è possibile e si abilita il pulsante quando è possibile.

Quando usi il controllo TitleBar con un controllo NavigationView , devi sostituire il pulsante Indietro della visualizzazione di spostamento con il pulsante Indietro della barra del titolo.

Ti consigliamo di:

  • Nascondere il pulsante Indietro nel NavigationView controllo . <NavigationView IsBackButtonVisible="Collapsed">
  • Mostra il pulsante Indietro nel TitleBar controllo . <TitleBar IsBackButtonVisible="True">
  • Gestire l'evento TitleBar.BackRequested per tornare indietro.

Si applica a

Vedi anche

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