简体   繁体   English

WP7中的PhoneApplicationFrame为null

[英]PhoneApplicationFrame is null in WP7

In windows phone 7, I'm using PhoneApplicationFrame to get the main frame as follows: 在Windows Phone 7中,我使用PhoneApplicationFrame来获取主框架,如下所示:

 // set the main layout
            if (frame == null)
            {
                frame = Application.Current.RootVisual as PhoneApplicationFrame;
            }

but the frame still null .. why? 但是框架仍然为空..为什么?

This was called in the MainPage constructor... At that time the application frame is not loaded yet. 这是在MainPage构造函数中调用的。当时应用程序框架尚未加载。 this cause the frame to be null 这导致框架为空

The solution is to create the frame in loaded event handler of the application 解决方案是在应用程序的已加载事件处理程序中创建框架

You need to do something like this: 您需要执行以下操作:

var currentPage = ((App)Application.Current).RootFrame.Content as PhoneApplicationPage;

Something similar was asked already here . 这里已经有人提出了类似的要求

私人PhoneApplicationFrame框架=(PhoneApplicationFrame)Application.Current.RootVisual;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM