WP8 개발에 익숙하며 웹 사이트에 액세스 할 수있는 WebBrowserControl이있는 앱을 만들고 있습니다. 앱이 백그라운드에서 작동 할 때 WebBrowser의 상태를 저장하고 싶지만 이렇게 할 수 없습니다. 즉, 사용자가 다시 열려고하는 경우 WebBrowser가 마지막 페이지를로드합니다. 내 코드 based in this은 다음과 같습니다.WebBrowser 컨트롤 상태 유지
웹 브라우저 속성 : 기본 및 소스가 비어 있습니다.
App.xaml.cs를 :
public partial class App : Application
{
//Url to store current address to maintain state when application is in background
public Uri Url { get; set; }
//Boolean to get if phone has been previously in background
public Boolean firstRun = true;
private void Application_Activated(object sender, ActivatedEventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
Uri currentUrl;
if (settings.TryGetValue("Url", out currentUrl))
Url = (Uri)settings["Url"];
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["Url"] = Url;
firstRun = false;
settings.Save();
}
MainPage.xaml.cs를는 :
public partial class MainPage : PhoneApplicationPage
{
Uri baseUrl = new Uri("http://my_url");
// Constructor
public MainPage()
{
InitializeComponent();
webBrowser.Navigated += new EventHandler<NavigationEventArgs>(WebBrowserNavigation);
App app = Application.Current as App;
if (app.firstRun)
{
webBrowser.Navigate(baseUrl);
}
}
async void WebBrowserNavigation(Object sender, NavigationEventArgs navArgs)
{
string url = navArgs.Uri.ToString();
App app = Application.Current as App;
app.Url = navArgs.Uri;
}
어떻게이 작업을 수행 할 수 없습니까? 어떤 오류가 발생하고 있습니까? – APerson
Windows 버튼 (배경으로 전환)을 밀고 응용 프로그램을 다시 열면 base_Url이 다시로드됩니다. –