简体   繁体   中英

PhoneApplicationFrame is null in WP7

In windows phone 7, I'm using PhoneApplicationFrame to get the main frame as follows:

 // 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. 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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