HardwareButtons_BackPressed在辅助页面上不起作用

时间:2016-05-08 15:13:45

标签: c# windows-phone-8.1 windows-phone

我有一个Windows Phone 8.1应用程序。它由2页组成。在第一页(MainPage.xaml)上有ListView和几个按钮。一个按钮允许多选列表中的项目。在代码中我处理回来,所以当用户在多选模式下单击时,应用程序将不会终止,而只是退出多选模式。

private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
    if (MultiSelectionButton.Visibility == Visibility.Collapsed)
    {
        DeleteSelectionButton.Visibility = Visibility.Collapsed;
        MultiSelectionButton.Visibility = Visibility.Visible;
        TripListView.SelectionMode = ListViewSelectionMode.None;
        TripListView.IsItemClickEnabled = true;

        e.Handled = true;
    }
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    HardwareButtons.BackPressed += HardwareButtons_BackPressed;
    this.navigationHelper.OnNavigatedTo(e);
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
    this.navigationHelper.OnNavigatedFrom(e);
}

在第二页(HubPage.xaml)上有Hub控件,HubSection和HubSection ListView。与第一页类似,我不想从选择模式返回上一页。

private void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
       if (_PeopleListViewInstance.SelectionMode == ListViewSelectionMode.Multiple)
       {
            _PeopleListViewInstance.SelectionMode = ListViewSelectionMode.None;
             DeleteSelectionButton.Visibility = Visibility.Collapsed;
             MultiSelectionButton.Visibility = Visibility.Visible;
             _PeopleListViewInstance.IsItemClickEnabled = true;

             e.Handled = true;
       }
 }

protected override void OnNavigatedTo(NavigationEventArgs e)
{
      _vm.Trip = (Trip) e.Parameter;
      DataContext = _vm;

      HardwareButtons.BackPressed += HardwareButtons_BackPressed;
      this.navigationHelper.OnNavigatedTo(e);
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
     HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
     this.navigationHelper.OnNavigatedFrom(e);
}

第一页上的代码工作正常,但第二页上没有。

我做错了什么?

0 个答案:

没有答案