public MainPage()
{
InitializeComponent();
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
private void b1_Click(object sender, RoutedEventArgs e)
{
string url = trackingtb.Text;
LoadSiteContent("http://www.mywebsite.com");
}
public void LoadSiteContent(string url)
{
//create a new WebClient object
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCallback2);
client.DownloadStringAsync(new Uri(url));
}
private void DownloadStringCallback2(Object sender, DownloadStringCompletedEventArgs e)
{
// If the request was not canceled and did not throw
// an exception, display the resource.
if (!e.Cancelled && e.Error == null)
{
output.Text= (string)e.Result;
//If you get the cross-thread exception then use the following line instead of the above
//Dispatcher.BeginInvoke(new Action (() => textBlock1.Text = (string)e.Result));
}
}
我正在尝试下载网站的 html 内容。由于某种原因,此代码不起作用。我希望 windows phone 7 和 windows phone 8 使用相同的东西。
谢谢。