我正在开发一个应用程序,我会加载一个不在clientbin文件夹中但在我服务器中的文件夹中的图像。我会做这样的事情 BitmapImage bit = new BitmapImage(); string path =“c:/image.png”; bit.UriSource = new Uri(path,UriKind.Absolute); identity.Source = bit; 但它不起作用。任何想法? 感谢
答案 0 :(得分:1)
尝试:
Image.Source = New Imaging.BitmapImage(New Uri(“http://www.Pic.jpg”,UriKind.Absolute))
您不希望将其包含在项目中,否则.xap会变得非常庞大。
答案 1 :(得分:0)
Silverlight应用程序在客户端上运行,而不是在服务器上运行,因此引用您尝试执行的路径时,实际上将指向运行应用程序的客户端计算机上的路径。但是,由于安全原因,Silverlight无权从客户端磁盘读取或写入客户端磁盘。隔离存储功能是例外。
因此,您可以选择Bill或WebService提供的第一个答案,这个答案实现起来比较复杂。
IB。
答案 2 :(得分:0)
添加Bill的答案。您还可以使用以下帮助程序方法来使用服务器端资源,该方法派生自xap文件的位置。
public static string GetUrlForResource(string resourcePage)
{
var webUrl = Application.Current.Host.Source.ToString();
//Get ClientBin Directory
var stub = webUrl.Substring(0, webUrl.LastIndexOf("/"));
//Get application root.
stub = stub.Substring(0, stub.LastIndexOf("/") + 1);
//Append the application root to the resource page.
webUrl = stub + resourcePage;
return webUrl;
}
要像Bill的回答一样使用它,请使用以下内容:
Image.Source = new Imaging.BitmapImage(new Uri(GetUrlForResource("images/myimage.png"), UriKind.Absolute));