做silvelight也有一段时间了,相册、游戏,刚刚完成的showcase这个小程序算是一个阶段了。这里就以showcase这个项目来做一下CaseStudy。
数据篇-加载图片
beta1到beta2中加载图片的方法有些改变。
private void LoadImage(String MediaUrl)
{
Uri uri = new Uri(HtmlPage.Document.DocumentUri, MediaUrl);
WebClient imgClient = new WebClient();
imgClient.OpenReadCompleted += new OpenReadCompletedEventHandler(imgClient_OpenReadCompleted);
imgClient.OpenReadAsync(uri);
}
void imgClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(e.Result);
xImage.Source = bi;
}
}
{
Uri uri = new Uri(HtmlPage.Document.DocumentUri, MediaUrl);
WebClient imgClient = new WebClient();
imgClient.OpenReadCompleted += new OpenReadCompletedEventHandler(imgClient_OpenReadCompleted);
imgClient.OpenReadAsync(uri);
}
void imgClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(e.Result);
xImage.Source = bi;
}
}
另一种方法
Uri uri = new Uri(HtmlPage.Document.DocumentUri, MediaUrl);
ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);
xImage.SetValue(Image.SourceProperty, img);
ImageSource img = new System.Windows.Media.Imaging.BitmapImage(uri);
xImage.SetValue(Image.SourceProperty, img);
作者:nasa
出处:nasa.cnblogs.com
联系:nasa_wz@hotmail.com
QQ:12446006