以下代码编译但不显示网站的文字或照片。我只想运行一个涉及与Silverlight进行HTTP通信的程序。知道为什么我没有让网站显示?我只是在textBlock中出现“错误发生”而不是显示
namespace SilverlightApplication4
{
public partial class MainPage : UserControl
{
string baseUri = "http://yahoo.com";
WebClient client = new WebClient();
public MainPage()
{
InitializeComponent();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
client.DownloadStringAsync(new Uri(baseUri));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
textBox.Text = "Using WebClient: "+ e.Result;
else
{
textBox.Text = e.Error.Message;
textBlock.Text = "error occurred";
}
}
}
}