Bug 26255 - Can not disable back button in Windows Phone
Summary: Can not disable back button in Windows Phone
Status: VERIFIED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.1
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 26186 ()
Depends on:
Blocks:
 
Reported: 2015-01-21 17:25 UTC by Cody Beyer (MSFT)
Modified: 2015-08-31 17:36 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED ANSWERED

Description Cody Beyer (MSFT) 2015-01-21 17:25:40 UTC
### Description

When attempting to disable the back action of the back button, the button will be disabled in Android but not in Windows Phone

### Test Case

https://www.dropbox.com/s/mli45qqe0rsa7x7/BackButtonIssue.rar?dl=0

### Steps to Reproduce

1. Start the app.

2. Click on the label “Click to push page” (another xamarin forms page is pushed)

3. Click the hardware back button.


### Excepted Results

Such as on Android, the button is disabled. No navigation between xamarin pages (OK)

### Actual Results

On Windows Phone 8 the button is NOT disabled. The navigation between xamarin pages works (NOT OK) and when the root page is reached, the main WP page (native page) is also closed (NOT OK)

### Version 

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0447006-02904
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0447006-02904
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0447006-02904
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0447006-02904
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0447006-02904
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0447006-02904
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0447006-02904
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0447006-02904
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.9.236.0 (d6a2cae)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.6.0.0 (eb24bdcf5cba2c12b673a07e0a8cce368b9563b3)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 1 asimk 2015-01-22 11:48:46 UTC
I have checked this issue with the help of Sample App attached to Bug description and observed that in Android device/emulator HARDWARE Back Button is not working (however, Back button of application is working fine) and it is correct behavior as per bug description.

But when I check same thing on WindowsPhone device/emulator, the HARDWARE Back button is working and we are able to navigation between xamarin
pages by clicking HARDWARE Back Button(not OK) and when the root page is reached, on clicking HARDWARE Back Button, application get closed(not OK), and as per bug description it is not expected behavior. 

Additional info:
When we move on next page of the appication on windows device, application Back button does not appear. However, for android we are getting Back button on next page. Below are the screen for the same:

Android: http://www.screencast.com/t/m20vvnHao
Windows: http://screencast.com/t/RFMU0MzW8S

Environment Info:
Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.7.248.0 (8ca7d11db8a6f874c6cd2de6d9ca0f511867ce91)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.18.1.3 (5474129af31e9d3a86cb7482c7c5c7a30ad315f1)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.4.0.0 (209abebbd8f1a292d042420edb45fa5fbd3f017b)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 2 Jason Smith [MSFT] 2015-01-27 02:14:00 UTC
How exactly is this repro supposed to disable the back button?  I see it working on both Android and WinPhone just fine?
Comment 3 Jason Smith [MSFT] 2015-01-27 02:14:56 UTC
Oh I see they are using the native APIs to do it, this wont work.
Comment 4 Jason Smith [MSFT] 2015-01-27 02:16:21 UTC
Replace your second page with the following code to disable the back button while it is visible:

class SecondPage : ContentPage
{
	protected override bool OnBackButtonPressed ()
	{
		return true;
	}
}
Comment 5 Jason Smith [MSFT] 2015-01-27 02:16:45 UTC
Answered by above comment
Comment 6 Jason Smith [MSFT] 2015-01-27 02:32:31 UTC
*** Bug 26186 has been marked as a duplicate of this bug. ***
Comment 7 asimk 2015-02-17 09:11:02 UTC
I have checked this issue with the help of Comment-4 and observed that back button is disabled when I write code which is mentioned in Comment-4.
I have checked this issue with 1.3.4.6331-pre4.

Environment Info:
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

Xamarin   3.9.296.0 (d66d164)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.6.1.0 (3b3ef438017c7ecf486defa9e01567a5f2b3cb2a)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 8 Scott Davis 2015-08-31 17:36:45 UTC
Since OnBackButtonPressed() is not async, how do you prompt the user if they want to exit the application or cancel the back navigation?  

I found someone else had the exact same question. 
http://stackoverflow.com/questions/32163471/confirmation-dialog-on-back-button-press-event-xamarin-forms