如何结合Silverlight中的一个图像,当我格式化URI? [英] How do I format a URI when binding an Image in Silverlight?

查看:156
本文介绍了如何结合Silverlight中的一个图像,当我格式化URI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直没能找到一个答案。

I haven't been able to find an answer to this.

我有中有图像路径数据库(图像/ myImage.jpg这个参数)。这些图像在我的asp.net网站,也是我在哪里举办SL存在。我想这些图像结合到我的列表框控制,使得所述图像的显示。

I have a database that has image paths in it ("images/myimage.jpg"). These images exist on my asp.net site which is also where I host the SL. I want to bind these images to my ListBox control so that the image displays.

我已阅读,因为我有一个字符串值,图像/ myImage.jpg这个参数,我需要将其转换为位图图像。我已经这样做了:

I have read that since I have a string value, "images/myimage.jpg", that I need to convert it to a BitMap image. I have done this:

在XAML:

 <Image Source="{Binding ImageFile, Converter={StaticResource ImageConverter}}"/>

该ImageConverter类:

The ImageConverter class:

    public object Convert(object value, Type targetType,
                                  object parameter, CultureInfo culture)
            {
                try
                {
                    Uri source= new Uri(value.ToString());
                    return new BitmapImage(source);
                }
                catch(Exception ex)
                {
                    return new BitmapImage();
                }
            }

创建URI时,URI的格式无法确定我得到一个错误。我究竟做错了什么?如果我创建一个开放的,看起来像这样:的http://本地主机:49723 /图像/ myimage.jpg ,它工作得很好。

为什么不只是图像/ myImage.jpg这个参数的工作?

Why doesn't just "images/myimage.jpg" work?

推荐答案

在Silverlight媒体相对路径是古怪,使他们能够工作相同(古怪)的方式,WPF路径做。相对路径是相对于XAP文件,而不是应用程序根目录。

Relative paths to media in Silverlight are wacky so they can work the same (wacky) way that WPF paths do. Relative paths are relative to the XAP file, not the app root.

一个技巧就是<一个href=\"http://wildermuth.com/2008/06/23/Silverlight%5Fs%5FXAML%5FRelative%5FURI%5Fs%5Fand%5FSite%5Fof%5FOrigin\"相对=nofollow>移动您的XAP到你的网站的根源,所以媒体的路径将是相对于根。

One trick is to move your XAP to the root of your website, so media paths will be relative to the root.

请参阅在Silverlight我相对URI的帖子<一个href=\"http://weblogs.asp.net/jgalloway/archive/2008/09/11/silverlight-and-relative-uri-s-for-image-and-video-sources.aspx\"相对=nofollow>这里。

See my post on relative URI's in Silverlight here.

这篇关于如何结合Silverlight中的一个图像,当我格式化URI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆