Windows Phone 8 SDK - Issue with screen locking, and application starting over

流过昼夜 提交于 2019-12-12 02:54:53

问题


I have an application with a webbrowser control in it. When I navigate in that control then step away for a bit, then come back to it (after unlocking the screen due to inactivity), the first/original page shows up again. How can I maintain the state of the browser?


回答1:


Define a public property Url in App.xaml.cs to store an Url

public Uri Url { get; set; }

On WebBrowser_LoadCompleted event: save WebBrowser.Source property which contains the current loaded Url to above Url property of Application class.

App app = Application.Current as App; 
app.Url = WebBrowser.Source;

On Application_Deactivated event (send app to background), save current app's state to IsolatedStorage

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["Url"] = Url;
settings.Save();

On Application_Launching event (resume app), pull the stored data back

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
Url currentUrl;
if (settings.TryGetValue("Url", out currentUrl)) 
   Url = (Uri)settings["Url"];

Then from the restored Url, you can re-load the last navigated page.

App app = Application.Current as App;
WebBrowser.Navigate(app.Url);



回答2:


You can try this:

bool isNew = true;

protected override void OnNavigatedTo(NavigationEventArgs e)
     {
        base.OnNavigatedTo(e);
        isNew = false;
}

this property will be maintained until your page is closed, so you can use it to test if this is the first time your page is navigated to.



来源:https://stackoverflow.com/questions/16514046/windows-phone-8-sdk-issue-with-screen-locking-and-application-starting-over

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!