使用 Silverlight 2 WebClient 按需打开图像
我试图在用户想要的时候在我的 silverlight 应用程序上显示一些图像。 这些图像位于我的 silverlight 项目中的一个文件夹中,我不希望用户在第一次加载网页时下载所有图像。
我尝试了 OpenReadAsync 方法,该方法具有图像文件的相对地址,该图像文件位于名为 images 的文件夹中,其“构建操作”设置为“内容”,并且其“复制到输出 Direcoty”属性设置为“始终”。
但我在 OpenReadCompleted 事件中收到以下异常: 无法识别 URI 前缀。
这是我使用的代码:
Dim webClient As New WebClient
AddHandler webClient.OpenReadCompleted, AddressOf webClient_OpenReadCompleted
WebClient.AllowReadStreamBuffering = True
WebClient.OpenReadAsync(New Uri("images/myimage.jpg", UriKind.Relative))
谁能告诉我如何解决这个问题? 谢谢
I'm trying to show some images on my silverlight application whenever user wants to. The images are in a folder in my silverlight project and I don't want the user to download all of them when he/she loads the web page for the first time.
I have tried the OpenReadAsync method with a relative address to the image file which is in a folder named images and its Build Action is set to Content and also its "Copy to Output Direcoty" property is set to Always.
But I get the following exception in the OpenReadCompleted event:
The URI prefix is not recognized.
Here is the code I used:
Dim webClient As New WebClient
AddHandler webClient.OpenReadCompleted, AddressOf webClient_OpenReadCompleted
WebClient.AllowReadStreamBuffering = True
WebClient.OpenReadAsync(New Uri("images/myimage.jpg", UriKind.Relative))
Can anyone tell me how can I solve this problem?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先从 silverlight 项目中取出图像。 您希望图像位于 Web 项目中,那么您可以使用带有空源的普通图像标签,然后当您需要下载图像时,将源设置为 uri。
To start with take the images out of the silverlight project. You want the images to be in the web project then you can use a normal image tag with an empty source, then when you need to download the image set the source to the uri.