c# - Unobscured event gives NullReferenceException -


i trying add unobscured event root phoneapplicationframe this:

phoneapplicationframe rootframe = (phoneapplicationframe)app.current.rootvisual; rootframe.unobscured += new eventhandler((s, e) => { dosomething(); }); 

but when run windows phone 8 app gives me nullreferenceexception in second line of code sample. there other way this?

you need careful when access rootvisual may still null. example, null in main page constructor. rootvisual set in completeinitializephoneapplication method in app.cs file.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -