1.瀏覽歷史
手柄導航中事件在事件處理WebBrowser控件,並與保存的URL在獨立存儲文件的文本格式。下面是代碼。
在XAML
<phone:WebBrowser Navigated="WebBrowser_Navigated" ... >
事件處理程序的代碼背後
private void WebBrowser_Navigated(object sender, NavigationEventArgs e)
{
using (IsolatedStorageFile storeFile= IsolatedStorageFile.GetUserStoreForApplication())
{
StreamWriter sr = new StreamWriter(new IsolatedStorageFileStream("Browse_History.txt", FileMode.Append, storeFile));
sr.WriteLine(e.Uri.ToString());
sr.Close();
}
}
以下方法
將讀取瀏覽器歷史記錄從本地存儲
private List<string> ReadHistory()
{
List<string> history = new List<string>();
using (IsolatedStorageFile storeFile = IsolatedStorageFile.GetUserStoreForApplication())
{
if (storeFile.FileExists("Browse_History.txt"))
{
using (StreamReader reader = new StreamReader(new IsolatedStorageFileStream("Browse_History.txt", System.IO.FileMode.Open, FileAccess.Read, storeFile)))
{
var uri = reader.ReadLine();
while (!string.IsNullOrEmpty(uri))
{
history.Add(uri);
uri = reader.ReadLine();
}
reader.Close();
return history;
}
}
}
return null;
}
你將不得不增加一些缺失的組件在頂部使用陳述
using System.IO.IsolatedStorage;
using System.IO;
2. Favorties
我想你想保存上的按鈕點擊與當前打開的頁面網址收藏夾。在按鈕上單擊事件處理程序編寫以下代碼
private void btnSaveToFavorties_Click(object sender, RoutedEventArgs e)
{
using (IsolatedStorageFile appStore = IsolatedStorageFile.GetUserStoreForApplication())
{
StreamWriter sr = new StreamWriter(new IsolatedStorageFileStream("Browser_Favorties.txt", FileMode.Append, appStore));
sr.WriteLine(webBrowser.Source.ToString());
sr.Close();
}
}
及以下的代碼加載所有favorties
private List<string> LoadFavoirties()
{
List<string> history = new List<string>();
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (appStorage.FileExists("Browser_Favorties.txt"))
{
using (StreamReader reader = new StreamReader(new IsolatedStorageFileStream("Browser_Favorties.txt", System.IO.FileMode.Open, FileAccess.Read, appStorage)))
{
var uri = reader.ReadLine();
while (!string.IsNullOrEmpty(uri))
{
history.Add(uri);
uri = reader.ReadLine();
}
reader.Close();
return history;
}
}
}
return null;
}
希望這有助於
我將如何diplay歷史和收藏夾 – Aadarsh
的保存目錄沒有這個力幫助它的Windows Phone 8碼 – Aadarsh