Windows Phone - 返回键

Windows Phone应用程序需要符合一些列的Guidelines,其中"返回键"是一个容易出问题的地方。

 

<<UI Design and Intercation Guide for Windows Phone 7>> v2.0中这样描述:

 

 

The hardware Back Button is used to navigate back on pages (screens) within an application or between applications. The application allows the framework to perform the operation when the button is pressed. Also, the Back Button can be used to close menus, dialogs, navigate to a previous page, exit a search operation, or even switch applications. However, the principal usage is to navigate from the current page to the previous page.

See the Navigation, Frames, and Pages topic for more information about the page navigation model in Windows Phone 7.

When a user navigates back out of the root page of an application, the application will terminate.

The Back Button will not work as a backspace key to delete text input.

 

 

See the Navigation, Frames and Pages topic for additional guidance.

Developers should only implement Back Button behaviors that navigate back or dismiss context menus or modal dialog boxes. All other implementations are prohibited.

 

SDK 7.0/7.1 文档中的相关描述是:

 

The hardware Back button is used to go back within an application or between applications. Also, the Back button can close an on-screen keyboard, menus, dialogs, navigate to a previous page, exit a search operation, or even switch applications. However, the principal usage is to move from a current screen to the previous screen.

 

总之,"返回键"只能用于返回上一页面。只是在有键盘、context菜单或弹出窗口时,这个返回操作是关闭键盘、取消context菜单或者弹出窗口。

 

如果页面中有弹出窗口,按"返回键"应取消弹出窗口,而不是退回到上一页面,Page类提供了可重载的OnBackKeyProcess方法,可供处理此逻辑:

 

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { if (popup.IsOpen) { popup.IsOpen = false; e.Cancel = true; } base.OnBackKeyPress(e); } 

 

 

有些情况下需要提醒用户是否要退出当前页面(返回上一页面),例如提醒用户保存当前页。此时可重载OnBackKeyProcess方法如下:

 

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { if (_isNewList) { if (!popupSavePromotion.IsOpen)//promotion not opened yet, show it { e.Cancel = true; popupSavePromotion.IsOpen = true; } else if (popupSavePromotion.IsOpen)//promotion already showed, if back key hit again, then close promotion and allow back key process continue { popupSavePromotion.IsOpen = false; } } base.OnBackKeyPress(e); } 

 

用户第一次按下"返回键"时弹出提示窗口,此时,用户再次按下"返回键"时,返回上一页面。

 

 

 

你可能感兴趣的:(Windows Phone - 返回键)