image

 

简单描述Sliverlight程序,就是在一个Frame里不停地换Page。在App.xaml.cs里,那个RootFrame(VisualRoot)就是PhoneApplicationFrame类型。

MSDN上关于PhoneApplicationFrame的解释已经做得简洁易读:http://msdn.microsoft.com/en-us/library/ff402536%28v=VS.92%29.aspx

我就不再赘述了,只简单总结一下:

PhoneApplicationFrame掌管着:

页面上方的Status Bar和下方的Application Bar

监听事件:页面方向的切换(Portrait/Landscape),Back按钮被按下,由来电等触发的Obscured/UnObscured等。其中大多事件都能由Page监听,在XAML里直接指定event handler就很方便,但是Obscured/UnObscured事件无法在Page中找到,这才需要在code behind里用到PhoneApplicationFrame,代码如下:

PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
frame.Obscured += new EventHandler<ObscuredEventArgs>(frame_Obscured);
frame.Unobscured += new EventHandler(frame_Unobscured);

 

当Obscured发生时,无法知道具体由什么中断的,只能知道是不是由锁屏中断的:

void frame_Obscured(object sender, ObscuredEventArgs e)
{
    if (e.IsLocked) // 仅能判断是否是锁屏
    {
    }
}
Obscured事件触发的时机

例如当电话来的时候就会触发Obscured事件,如果你正在玩游戏之类的,便可以在obscured的hander中使游戏暂停。这时候还没触发Deactived事件,只有当用户按下接听按钮时,才会触发Deactived事件。如果是锁屏的话,Obscured事件也会先于Deactivated事件发生。

posted on 2011-12-01 22:06  MainTao  阅读(946)  评论(0编辑  收藏  举报