Windows Phone 7- 返回键

//"返回键"只能用于返回上一页面。只是在有键盘、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)