下面的代码编译,但它不显示网站的文本或照片。我只想运行一个涉及与 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";
}
}
}
}