簡體   English   中英

后退按鈕在XAML / W8中不起作用

[英]Back button not working in XAML / W8

我的頁面上有以下按鈕:

 <AppBarButton Grid.Column="0" x:Name="backButton" Icon="Back" Margin="10,26,0,-1"
                      Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}" 
                      IsEnabled="True"
                      Visibility="Visible"
                      Foreground="Green"

                      AutomationProperties.Name="Back"
                      AutomationProperties.AutomationId="BackButton"
                      AutomationProperties.ItemType="Navigation Button" Grid.Row="1" Grid.RowSpan="2" VerticalAlignment="Stretch"
                      />

該按鈕出現,但單擊它不會執行任何操作。 這被放置在應用程序的兩個頁面的第二個頁面上。 我按照NavigatonHelper.cs中的說明將其連接到第二頁,但是在第一頁中沒有做任何特殊的事情。 我想念什么?

我什至嘗試將Click屬性綁定到自定義函數:

 public void ClickGoBack(object sender, RoutedEventArgs routedEventArgs) {
        this.Frame.Navigate(typeof(HubPage));
    }

但是當我單擊按鈕時,這甚至從未被擊中。

您是否已檢查已定義的AppBarButton中存在的Click?

就像: <AppBarButton ... Click="ClickGoBack"></AppBarButton>

你應該用

if (this.Frame.CanGoBack)
{
    this.Frame.GoBack();
}

代替

this.Frame.Navigate(typeof(HubPage));

您可以這樣做對我來說要容易得多。

<AppBar><Button Style="{StaticResource BackButtonStyle}" Click="Click1"></Button>
    </AppBar>

還有你后面的代碼

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
    {
        Frame.GoBack();
    }

在XAML中與按鈕重疊的頂部網格之后放了一些東西-到目前為止,我還不了解“自然順序”的概念。 感謝大家的幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM