I can do this within code to load a bitmapimage located on the Server under ClientBin\Images folder:
var image = new BitmapImage(new Uri(Application.Current.Host.Source, "./Images/Default.JPG"));
However how do I do this within XAML itself? Is it even possible?
<Image x:Name="NewImage" Source="../Images/Default.JPG"/>
Many Thanks,
Did you try this:-
<Image x:Name="NewImage" Source="/Images/Default.JPG"/>
Urls in Xaml treat the folder from which the Xap is downloaded (ClientBin usually) as the root, i.e. the path "/" points actually at ClientBin.
You can't use a relative path in silverlight for an image on the server since the xap file is downloaded to the client, so the application is not actually running on the server.
you will have to use the full "http://mysite.com/myImage.jpg" path
Related
I have a wpf app with this folder structure:
In the HomeController, I want to access the Images folder. I want to store an image in the Images folder from the HomeController. How can I do this? I tried using pack origin but it takes me to bin.
This should do the trick:
pack://application:,,,/Images/image.png
Can be used in xaml or in code. For more detailed explanation you can review this Microsoft page about it.
In code: Uri uri = new Uri("pack://application:,,,/Images/image.png");
In xaml: <element attribute="pack://application:,,,/Images/image.png"/>
I use some images in ClientBin folder in my Silverlight 5 application. Everything is OK when I run it in browser, but when I change application to out of browser, images in program ClientBin are not displayed (I read them using new BitmapImage(new Uri(".....", UriKind.Relative)))
what is going wrong here? Should I place ClientBin folder next to my Out of Browser app? where is my OOB app? how can I solve this problem?
You will need to use an absolute Uri with a fully qualified url to your images. When Silverlight is running OOB, it's not running in the context of the web site hosting the xap file, so it has no idea of what the relative path is.
My Windows Store app/Metro/Win RT app downloads image from server on to some local folder. I need to bind Image control to the downloaded image at runtime.
The problem is that image doesn't show up unless I add it as a binary resource to the project.
My downloaded images are stored in ProjectFolder/Data/Media. Now, here is how I bind image source to image control.
<Image x:Name="WriterImage" Stretch="None" Source="{Binding Path=PersonData.Photo.MediaImageSource"></Image>
public ImageSource MediaImageSource
{
// Here _MediaUrl gets a value: ms-appx:///Data/Media/Writer1.jpg
BitmapImage source = new BitmapImage(new Uri(_MediaUrl));
}
This works only if I add Writer1.jpg as a resource to the project. If I remove it from the project, it doesn't show up.
Note that there are different URL schemes that your application can access:
ms-appx:/// is a read-only location, and refers to files that are included (compiled) with your application, such as resources.
ms-appdata:///local/ refers to local read-write storage for your application. If you are downloading files, my guess is that you should use this URL scheme.
For your example above, I would try using the following URL:
ms-appdata:///local/Data/Media/Writer1.jpg
See the following for more info about URL (URI) schemes: http://msdn.microsoft.com/en-us/library/windows/apps/jj655406.aspx
I seem to have a problem loading .dll files into my silverlight application.
this.pluginDownloader = new WebClient();
this.pluginDownloader.OpenReadCompleted += new OpenReadCompletedEventHandler(pluginDownloader_OpenReadCompleted);
this.pluginDownloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(pluginDownloader_DownloadProgressChanged);
String path = String.Format("http://localhost/Resources/Plugins/{0}.dll", this.pluginDetails.AssemblyName);
this.pluginDownloader.OpenReadAsync(new Uri(path, UriKind.Relative));
I can manually download the .dll assembly file by navigating to it (eg: http://localhost/Resources/Plugins/myAssembly.dll) but it just stalls the silverlight app when the above code is executed. This works when I launch the project in visual studio so it must be some setting in IIS7.
Anyone know how to fix this?
Thanks for answering Jeff... I tried relative paths also but that didn't work either. I thought an absolute URL would be the best thing to try as I can actually navigate and download the assembly file using the localhost link.
EDIT:
Got it working - if i replace localhost with the actual IP address of the server it works find
String path = String.Format("http://192.168.2.107/code/Platform/Website/Resources/Plugins/{0}.dll", this.pluginDetails.AssemblyName);
this.pluginDownloader.OpenReadAsync(new Uri(path, UriKind.Absolute));
I'd still like to know how to get it working using a relative path...
The relative path should work - i'm using a one in the same class to load an image
this.pluginImage.Source = new BitmapImage(new Uri("/Resources/Plugins/PluginTile/" + this.pluginDetails.ImageFilename, UriKind.Relative));
Strange...
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
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.